Note that there are some explanatory texts on larger screens.

plurals
  1. POBad Request when sending json object with authentication on android
    primarykey
    data
    text
    <p>I am getting the error <code>bad request</code> when I try to send a json object with authentication. I had a look at <a href="https://stackoverflow.com/questions/9389842/how-to-send-a-json-object-over-httpclient-request-with-android">How to send a JSON object over HttpClient Request with Android?</a> but it does not solve my problem.</p> <pre><code>public void getServerData() throws JSONException, ClientProtocolException, IOException { ArrayList&lt;String&gt; stringData = new ArrayList&lt;String&gt;(); DefaultHttpClient httpClient = new DefaultHttpClient(); ResponseHandler &lt;String&gt; resonseHandler = new BasicResponseHandler(); byte[] data = "myusername:mypassword".getBytes("UTF-8"); String encoding = Base64.encodeToString(data, Base64.DEFAULT); HttpPost postMethod = new HttpPost("http://url/email_check.json"); postMethod.setHeader(HTTP.CONTENT_TYPE, "application/json"); postMethod.setHeader("Authorization", "Basic " + encoding); JSONObject json = new JSONObject(); json.put("email","somebody@email.com"); postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8"))); String response = httpClient.execute(postMethod,resonseHandler); Log.e("response :", response); } </code></pre> <p>The line <code>String response = httpClient.execute(postMethod,resonseHandler);</code> causes a <code>ClientProtocolException</code> as follows:</p> <pre><code>cause: org.apache.http.client.HttpResponseException: Bad Request detailMessage: Bad Request stackState: (id=830103290336) stackTrace: null statusCode: 400 </code></pre> <p>Any idea what is wrong?</p>
    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.
 

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