0

I try to make put request to server with following code:

    HttpClient client = new DefaultHttpClient();
    HttpPut put= new HttpPut(SERVER_URL + "/subscribe");

    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("UserId", params.get("UserId")));
    pairs.add(new BasicNameValuePair("Endpoint", params.get("Endpoint")));
    pairs.add(new BasicNameValuePair("SessionKey", params.get("SessionKey")));
    pairs.add(new BasicNameValuePair("SessionSecret", params.get("SessionSecret")));
    pairs.add(new BasicNameValuePair("Token", params.get("Token")));
    pairs.add(new BasicNameValuePair("CultureInfo", params.get("CultureInfo")));
    put.setEntity(new UrlEncodedFormEntity(pairs));
    put.setHeader("Content-Type", "application/json");
    HttpResponse response = client.execute(put);
    response.getStatusLine();

server returns 500 code response in getStatusLine method, so I want to know the full request text to see what request was created. Any suggestions how it can be done?

Paul
  • 123
  • 1
  • 8

1 Answers1

1

turn on logs for WIRE and logs for HEADERS

you need to read posts like one above in order to figure out how to toggle the full http logs for the connections you are trying to test. As you can see in the sample below , once you get the logs , you can see everything in the headers and everything that goes across the wire ( client to server & server to client )

A suggestion for using CURL - if you develope using these tools, you can think about using a curl client in order to model the conversation between client / server before you code the android. Then, with the aid of the android logs, you can send via android, exactly what you were sending from a CLI curl client, thus avoiding all the murky issues with RC=500.

details with logging turned on:

./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "HTTP/1.1 200 OK[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "Content-Type: application/json; charset=utf-8[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "Content-Disposition: attachment[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "Date: Fri, 16 Nov 2012 01:05:15 GMT[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "Expires: Fri, 16 Nov 2012 01:05:15 GMT[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "Cache-Control: private, max-age=0[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "X-Content-Type-Options: nosniff[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "X-Frame-Options: SAMEORIGIN[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "X-XSS-Protection: 1; mode=block[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "Server: GSE[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "Transfer-Encoding: chunked[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "71[\r][\n]"
./speechapi_1:D/ch.boye.httpclientandroidlib.wire( 6461): << "{"status":0,"id":"d70bb25a44fe84fb8bf7acf10c73b869-1","hypotheses":[{"
utterance":"hi","confidence":0.83725035}]}[\n]"
Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
  • I dont want to use adb via command prompt, I debug using eclipse. – Paul Mar 20 '13 at 17:05
  • So how can I add run "adb shell setprop log.tag.org.apache.http VERBOSE" under eclipse? – Paul Mar 20 '13 at 17:18
  • if you build apps using http, you will need to be able to turn on WIRE and HEADER debug. Using eclipse should be fine. WIRE level and HEADER level http logs are hi-value test data to a developer and you just need to turn the extra logging on when you need it. – Robert Rowntree Mar 20 '13 at 20:24
  • BTW - i debug in eclipse as well. I toggle full wire and header logging by swapping jar files and rebuilding the app. https://code.google.com/p/httpclientandroidlib/ is the client i use. see here for plain eclipse : http://icodesnip.com/snippet/bash/java-commons-logging-httpclient-simplelog – Robert Rowntree Mar 20 '13 at 20:43
  • Ok, I did that but all information provided by ch.boye.httpclientandroidlib was: "class ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient(31744): Attempt 1 to execute request" and "Connection can be kept alive indefinitely". Why no outputed info about request as on your example? – Paul Mar 21 '13 at 12:00
  • hmm. that would be part of the Client / server http conversation. but its only part. remember that http is a protocol for communication covering lots of msgs ( C-to-S requests , S-to-C responses ) and u need to understand the context of the conversation and the details of each message in that conv. I put up a full pastbin on a conversation over a single connection and POST. http://pastebin.com/Qy4hm3pH << or >> indicates direction of message in the conversation. You may need to do more learning on http protocol.... – Robert Rowntree Mar 21 '13 at 15:13