Skip to content Skip to sidebar Skip to footer

Android Testing Httppost String For Debugging Purposes

I'm trying to send data from my phone to mysql with HttpPost, but I don't have any server set up, so I was wondering if I can see what I'm sending exactly, and what it looks like.

Solution 1:

Depending on the version of httpclient that you are using, there are going to be various ways of turning on 2 critical loggers:

httpclient.wire.header httpclient.wire

In one type of client, you can use java system properties to activate DEBUG level logging on the respective loggers almost always used by an HttpClient (headers & wire )...

 System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug");          System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");

above will not work in all situations. For example on android, i use the client and, in order to activate logging for WIRE and for HEADERS, i have to recompile the 3rd party package, changing class= ch.boye.httpclientandroidlib.androidextra.HttpClientAndroidLog ( Log DEBUG ON | OFF )

sample block of logcat with both loggers turned on gives complete view of what's happening under the covers of http...

I/PicasaAlbumService(2218):StartingPHOTOService.onHandleIntentcom.b2bpo.media.action.ALBUMLISTI/ActivityManager(163):Displayed com.b2bpo.media/.ApplyGeoActivity:+1s349ms(total+5s944ms)D/dalvikvm(2218):GC_CONCURRENTfreed292K,44%free3625K/6407K,external387K/519K,paused2ms+3msD/classch.boye.httpclientandroidlib.impl.client.DefaultHttpClient(2218):Attempt1toexecuterequestD/classch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection(2218):Sending request:GET/data/feed/api/user/default?fields=entry%2Ftitle%2Centry%2Flink%5B%40rel%3D%22http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23feed%22%5D&start-index=1&max-results=10&alt=jsonHTTP/1.1D/ch.boye.httpclientandroidlib.wire(2218):>>"GET /data/feed/api/user/default?fields=entry%2Ftitle%2Centry%2Flink%5B%40rel%3D%22http%3A%2F%2Fschemas.google.co
m%2Fg%2F2005%23feed%22%5D&start-index=1&max-results=10&alt=json HTTP/1.1[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):>>"GData-Version: 2[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):>>"Host: picasaweb.google.com[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):>>"Connection: Keep-Alive[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):>>"Authorization: OAuth null[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):>>"[\r][\n]"D/ch.boye.httpclientandroidlib.headers(2218):>>GET/data/feed/api/user/default?fields=entry%2Ftitle%2Centry%2Flink%5B%40rel%3D%22http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23feed%22%5D&start-index=1&max-results=10&alt=jsonHTTP/1.1D/ch.boye.httpclientandroidlib.headers(2218):>>GData-Version:2D/ch.boye.httpclientandroidlib.headers(2218):>>Host:picasaweb.google.comD/ch.boye.httpclientandroidlib.headers(2218):>>Connection:Keep-AliveD/ch.boye.httpclientandroidlib.headers(2218):>>Authorization:OAuthnullD/ch.boye.httpclientandroidlib.wire(2218):<<"HTTP/1.1 403 Forbidden[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"Expires: Fri, 17 Feb 2012 18:07:42 GMT[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"Date: Fri, 17 Feb 2012 18:07:42 GMT[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"Cache-Control: private, max-age=0, must-revalidate[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"Content-Type: text/plain[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"X-Content-Type-Options: nosniff[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"X-Frame-Options: SAMEORIGIN[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"X-XSS-Protection: 1; mode=block[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"Set-Cookie: S=photos_html=UJsnbriEAQZm6J0wEJjfgA; Domain=.google.com; Path=/; Secure; HttpOnly[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"Server: GSE[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"Transfer-Encoding: chunked[\r][\n]"D/ch.boye.httpclientandroidlib.wire(2218):<<"[\r][\n]"D/classch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection(2218):Receiving response:HTTP/1.1403ForbiddenD/ch.boye.httpclientandroidlib.headers(2218):<<HTTP/1.1403ForbiddenD/ch.boye.httpclientandroidlib.headers(2218):<<Expires:Fri,17Feb2012 18:07:42 GMTD/ch.boye.httpclientandroidlib.headers(2218):<<Date:Fri,17Feb2012 18:07:42 GMTD/ch.boye.httpclientandroidlib.headers(2218):<<Cache-Control:private,max-age=0,must-revalidateD/ch.boye.httpclientandroidlib.headers(2218):<<Content-Type:text/plainD/ch.boye.httpclientandroidlib.headers(2218):<<X-Content-Type-Options:nosniffD/ch.boye.httpclientandroidlib.headers(2218):<<X-Frame-Options:SAMEORIGIND/ch.boye.httpclientandroidlib.headers(2218):<<X-XSS-Protection:1;mode=blockD/ch.boye.httpclientandroidlib.headers(2218):<<Set-Cookie:S=photos_html=UJsnbriEAQZm6J0wEJjfgA;Domain=.google.com;Path=/;Secure;HttpOnlyD/ch.boye.httpclientandroidlib.headers(2218):<<Server:GSED/ch.boye.httpclientandroidlib.headers(2218):<<Transfer-Encoding:chunkedD/classch.boye.httpclientandroidlib.impl.client.DefaultHttpClient(2218):Connectioncanbekeptaliveindefinitely

Solution 2:

in your IDE, such as Eclipse, put a breakpoint at httpclient.execute(httppost);

and then in the Expressions window, add the httppost variable, to see what the value is.

Now you can get rid of all that logging stuff

Post a Comment for "Android Testing Httppost String For Debugging Purposes"