1

我向服务器发出请求他应该返回 JSON,但结果我得到“404”并且......

<?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(
                ("estafeta@62e12548-0a68-4999-960b-a3bb3c44675c: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?帮助

4

1 回答 1

0

可能您忘记设置要接收的内容类型 get.setHeader("Content-type", "application/json; charset=utf-8");

于 2012-10-10T08:01:16.110 回答