Note that there are some explanatory texts on larger screens.

plurals
  1. PO411 Content-Length Required
    text
    copied!<p>I am trying to do a POST using the Android Apache HttpClient but it is returning error 411 Content-Length Required. Here is the code.</p> <pre><code> HttpClient httpClient = new DefaultHttpClient(); HttpPost request = new HttpPost("https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/tokenservice"); request.addHeader("Authorization","Basic "+ Base64.encodeToString((appId+":"+ appSecret).getBytes(),Base64.DEFAULT)); List&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;(); postParameters.add(new BasicNameValuePair("grant_type", "authorization_code")); postParameters.add(new BasicNameValuePair("code", code)); postParameters.add(new BasicNameValuePair("scope", "https://uri.paypal.com/services/paypalhere")); UrlEncodedFormEntity entity; entity = new UrlEncodedFormEntity(postParameters); request.setEntity(entity); HttpResponse response = httpClient.execute(request); Log.d("HTTPStatus",response.getStatusLine().toString()); InputStream bufferedReader = response.getEntity().getContent(); StringBuffer stringBuffer = new StringBuffer(""); byte[] line = new byte[1024]; while (bufferedReader.read(line) &gt; 0) { stringBuffer.append(new String(line)); } bufferedReader.close(); Log.d("str",stringBuffer.toString()); </code></pre> <p>I have tried adding the line:-</p> <pre><code> request.addHeader("Content-Length",Long.toString(entity.getContentLength())); </code></pre> <p>But then I get a 'org.apache.http.ProtocolException: Content-Length header already present' error instead. This must mean that the HttpClient is already sending the Content-Length. Unfortunatley I have no access to the server side. Any ideas why it would be returning these errors?</p>
 

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