0

オブジェクトが空白になりBufferedReaderました。コードをデバッグすると、実際にはHttpEntityオブジェクトも空のように見えることがわかりました。

コードの私の部分は次のとおりです。

//HTTPリクエストの作成

try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Content-Type", "application/json");
            httpPost.setHeader("Accept", "JSON");

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            long len = httpEntity.getContentLength();
            is = httpEntity.getContent();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (UnknownHostException e){
            e.getMessage();
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "UTF-8"), 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());
        }

PC ブラウザーで自分の URL にアクセスすると、JSON 応答が返され、[http://jsonlint.com/][1] でも返されます。

正確な問題は何ですか、私には理解できません

4

1 に答える 1

0

応答ステータスを確認し、応答の読み取りを開始します

 HttpResponse httpResponse = httpClient.execute(httpPost);
 if(httpResponse .getStatusLine().getStatusCode() == SC_OK)
 {
   HttpEntity httpEntity = httpResponse.getEntity();
   long len = httpEntity.getContentLength();
   is = httpEntity.getContent();
  }
于 2014-02-18T04:56:38.940 に答える