無效響應我向服務器請求,他應該返回JSON 但結果我得到「404」和...JSON解析從服務器
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Service</title>
</head>
<body>
<div id="content">
<p class="heading1">Service</p>
<p>Endpoint not found.</p>
</div>
</body>
</html>
我的要求JSON:
public JSONObject getJSONFromUrl() {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = getNewHttpClient();
String auth = android.util.Base64.encodeToString(
("[email protected]:11111")
.getBytes("UTF-8"), android.util.Base64.NO_WRAP);
HttpGet get = new HttpGet(
"https://test2.estafeta.org/mobileestafeta/MobileSurveyReportsService.svc/LoadSurveyTasks?startRowVersion=AAAAAAAAAAA=&count=500");
get.addHeader("Authorization", "Basic " + auth);
HttpResponse httpResponse = httpClient.execute(get);
//httpResponse.getStatusLine().getStatusCode()
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
我需要得到JSON我做錯了嗎?幫助
如果你得到一個404的內容類型,這意味着你是不是調用正確的地址... – njzk2
查詢我已經正確寫入? –
我不認爲你的參數應該寫成這樣。使用UrlEncoder – njzk2