i am using following code to make an httpPost call but it is returning me 400 bad request
when i try to give following parameters in "simple rest client" in chrome extension it works fine any one guide me what mistake am i doing here?
Simple rest Client I entered the following:
URL: http://jon2012.com/api/register
Method: POST
Headers: No headers, as they are not required
Data: { "email": "[email protected]", "first_name":"Name" }
Android Code:
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject json = new JSONObject();
try{
HttpPost post = new HttpPost(url);
json.put("email", email);
json.put("first_name", name);
StringEntity se = new StringEntity( "JSON: " + json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
response = client.execute(post);
/*Checking response */
/*if(response!=null){
InputStream in = response.getEntity().getContent(); //Get the data in the entity
*/
int statusCode = response.getStatusLine().getStatusCode();
}
catch(Exception e){
e.printStackTrace();
// createDialog("Error", "Cannot Estabilish Connection");
}
any help would be appriciated
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…