Reputation:
This is the script that works:
curl -H 'content-type:application/json' -d '{"userrequest": {"username": "testname", "status": 1}}' http://http://employeestracking.appspot.com/clockin.add_clockin
This is what I tried to use in android: further,How can I see/debug the output?
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();
}
this is what i get from the server:
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"
41.132.228.221 - - [26/Jan/2012:01:18:55 -0800] "POST /clockin.add_clockin HTTP/1.1" 200 151 - "curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15" 0.1.0.1 - - [26/Jan/2012:01:31:52 -0800] "GET /tasks/train HTTP/1.1" 404 124 - "AppEngine-Google; (+http://code.google.com/appengine)" 41.132.228.221 - - [26/Jan/2012:01:37:17 -0800] "POST /clockin.add_clockin HTTP/1.1" 500 663 - -
Upvotes: 1
Views: 1907
Reputation:
I replaced
httpost.getParams().setParameter("data",data);
with:
StringEntity se = new StringEntity(data.toString());
httpost.setEntity(se);
and it worked
Upvotes: 3