我在使用 REST API 访问 ATG sessionconfirmationNumber 时遇到了一个问题,我正在使用 http urlconnection 来实现相同的目标,代码运行良好,我也得到了输出,但是 Json 响应中的结果是四舍五入的,因为数字很大。下面是代码。
try {
StrictMode.ThreadPolicy policy = new StrictMode.
ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
// Defined URL where to send data
// URL url = new URL("http://10.201.62.27:8080/Test-Servlet/TestServletAndroid?"+data);
URL url = new URL("http://52.70.41.98:7203/rest/model/atg/rest/SessionConfirmationActor/getSessionConfirmationNumber");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
HttpURLConnection httpConnection = (HttpURLConnection) conn;
Log.e("Connection", conn.toString());
httpConnection.setRequestMethod("GET");
httpConnection.setRequestProperty("Content-Type", "text/plain");
httpConnection.connect();
// Get the server response
reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while ((line = reader.readLine()) != null) {
// Append server response in string
sb.append(line + "\n");
}
response = sb.toString();
Log.v("ResponseVALID", response);
JSONObject json = new JSONObject(response);
Log.v("Tag0", json.toString());
scn = json.getLong("sessionConfirmationNumber");
/*String srr[] = response.split(":");
for(int i =0;i<srr.length;i++){
Log.v("TAG2:",srr[i]);
}
SCN=srr[1].replace("}", "");
SCN= SCN.trim();
Log.v("SCN ",SCN);
scn=Long.parseLong(SCN);*/
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
reader.close();
} catch (Exception ex) {
}
}
我在门户网站上遇到了与 angularjs 相同的问题,XMLHttp 请求帮助我实现了目标。
我可以使用来自 android studio 的 XMLHttp 请求吗?,如果可以!,请给我一些参考,因为我已经尝试过,但没有为我解决。
任何帮助,将不胜感激。