我收到的是HTML响应而不是JSON响应。我使用以下代码,但我收到的是HTML响应,如bf.readLine() 所示。这段代码有问题吗?还是API出了问题?
String uri = "http://192.168.77.6/Ivr_ABN_API/?id=" + mobile;
URL url;
Gson json = null;
try {
url = new URL(uri);
json = new Gson();
HttpURLConnection connection;
access_token = db.getAccessTokenFromDB();
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
System.out.println("URL:" + uri);
connection.setRequestProperty("Content-Type", "application/json");
int status = connection.getResponseCode();
resCode = Integer.toString(status);
System.out.println("status is " + status);
InputStream in = connection.getInputStream();
System.out.println("inputStreamer " + in);
BufferedReader bf = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
System.out.println("bf.readLine() - " + bf.readLine());
while ((output = bf.readLine()) != null) {
JSONObject obj = new JSONObject(output);
System.out.println("output is " + output);
resCode = obj.getString("resCode");
resDesc = obj.getString("COUNT");
}