Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpPost - ClientProtocolException
    primarykey
    data
    text
    <p>When I am posting http post JSON data to server , getting an exception <code>ClientProtocolException</code> . Can any one tell me what wrong with this piece of code ? </p> <p>Logcat</p> <pre><code>06-11 10:30:56.062: W/System.err(435): org.apache.http.client.ClientProtocolException 06-11 10:30:56.122: W/System.err(435): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557) 06-11 10:30:56.182: W/System.err(435): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653) 06-11 10:30:56.212: W/System.err(435): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627) 06-11 10:30:56.212: W/System.err(435): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616) 06-11 10:30:56.212: W/System.err(435): at com.vector.syncfunc.MainActivity.post(MainActivity.java:168) </code></pre> <p>Code:</p> <pre><code> private String post(String url) { String response = null; try { boolean exception = false; StringBuilder builder = new StringBuilder(); builder.append(getDeviceId()); builder.append("|||"); builder.append(getLastSyncDate()); builder.append("|||"); builder.append(getCurrentDateStr()); String dateStr = builder.toString(); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); //httpPost.setHeader("Host", url); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader(HTTP.CONTENT_TYPE, "application/json"); JSONObject jsonObject = new JSONObject(); String param = null; try { param = encrypt(dateStr); } catch (InvalidKeyException e1) { e1.printStackTrace(); exception = true; } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); exception = true; } catch (NoSuchPaddingException e1) { e1.printStackTrace(); exception = true; } catch (IllegalBlockSizeException e1) { e1.printStackTrace(); exception = true; } catch (BadPaddingException e1) { e1.printStackTrace(); exception = true; } if (exception) { return null; } try { jsonObject.put("encstring", param); } catch (JSONException e) { e.printStackTrace(); } httpPost.setHeader("Content-Length", ""+param.getBytes().length); StringEntity entity = new StringEntity(jsonObject.toString(), HTTP.UTF_8); entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httpPost.setEntity(entity); ResponseHandler responseHandler = new BasicResponseHandler(); HttpResponse httpResponse = httpclient.execute(httpPost, responseHandler); StatusLine line = httpResponse.getStatusLine(); if (line.getStatusCode() == 200) { HttpEntity httpEntity = httpResponse.getEntity(); InputStream inputStream = httpEntity.getContent(); response = readString(inputStream); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return response; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload