android - entity.getContentLength() returns -1 -


The object of BufferedReader is empty, when I debug my code, I suppose that In the HttpEntity object also looks like blank.

Here's my part of the code:

// create HTTP request

  try {// defaultHttpClient DefaultHttpClient HttpClient = new DefaultHttpClient (); Http post http post = new HTTP post (url); HttpPost.setHeader ("content-type", "app / json"); HttpPost.setHeader ("Accept", "JSON"); HttpResponse httpResponse = httpClient.execute (httpPost); HttpEntity httpEntity = httpResponse.getEntity (); Long LAN = httpEntity.getContentLength (); Is = httpEntity.getContent (); } Hold (unsupported encoding exception e) {e.printStackTrace (); } Hold (unknownhostexception e) {eagmesses (); E.printStackTrace (); } Hold (Client Protocol E) e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); } {BufferedReader Reader = Try New BufferedReader (New InputStreamReader ("UTF-8"), 8); Stringbilder sb = new stringbiller (); String line = null; While ((line = reader. Readline ())! = Null () {sb.append (row + "\ n"); }             is close(); Json = sb.toString (); } Hold (exception e) {Log.e ("buffer error", "error in changing result" + e.toString ()); }  

If I'm hitting my URL on a PC browser, it returns a JSON response, and [http://jsonlint.com/] [1]

What is the exact problem, I do not understand

Check the response status and after that Read the Feedback Feedback

  HTTPRPS.png httpResponse = httpClient.execute (httpPost); If (httpResponse .getStatusLine (). GetStatusCode () == SC_OK) {HttpEntity httpEntity = httpResponse.getEntity (); Long LAN = httpEntity.getContentLength (); Is = httpEntity.getContent (); }  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -