
Untitled
By: a guest on
May 4th, 2012 | syntax:
None | size: 2.00 KB | hits: 16 | expires: Never
cURL to httppost Java in Android and debug output from request
curl -H 'content-type:application/json' -d '{"userrequest": {"username": "testname", "status": 1}}' http://http://employeestracking.appspot.com/clockin.add_clockin
HttpParams httpParams = new BasicHttpParams();
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost httpost = new HttpPost("http://employeestracking.appspot.com/clockin.add_clockin");
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
System.out.println("2");
JSONObject data = new JSONObject();
JSONObject userrequest = new JSONObject();
HttpResponse response = null;
try {
userrequest.put("username","TestDemo");
userrequest.put("status",1);
data.put("userrequest", userrequest);
System.out.println(data);
httpost.getParams().setParameter("data",data);
try {
response = client.execute(httpost);
System.out.println(response);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
41.132.228.221 - - [26/Jan/2012:01:18:29 -0800] "POST /clockin.add_clockin HTTP/1.1" 400 663 - "curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15"
httpost.getParams().setParameter("data",data);
StringEntity se = new StringEntity(data.toString());
httpost.setEntity(se);