问题描述
我想从我的手机发送的数据与HttpPost MySQL的,但我没有任何服务器的架设,所以我在想,如果我可以看到我送准确,而且它是什么样子。我有点熟悉JSON和如何看那些喜欢。所以我很好奇,什么我会发送到MySQL用于调试目的。
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. I'm a little familiar with JSON and the likes of how those look. So I'm curious as to what I'd be sending to mysql for debugging purposes.
public void sendDataDetail(View v){
String name = nameText.getText().toString();
if(name.length()>0){
Log.w(TAG, name);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://site/post.php");
Log.w(TAG, "After HttpPost");
try{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
Log.w(TAG, "After list");
nameValuePairs.add(new BasicNameValuePair("location","Los Angeles"));
Log.w(TAG, "After location");
nameValuePairs.add(new BasicNameValuePair("item_name",name));
Log.w(TAG, "After item");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.w(TAG, "After nameValuePairs");
httpclient.execute(httppost);
nameText.setText(""); // clear text box, but this should be back to front page
}catch(ClientProtocolException e){
Log.w(TAG, e.getMessage());
}catch(IOException e ){
Log.w(TAG, e.getMessage());
}
}
}
正如你可以看到我有一堆原木,以测试它是否经过的每一行(不知道这甚至是必需= \\)。我在想,如果我能看到什么 httppost
的样子,但好像如果我这样做是行不通
As you can see I have a bunch of Logs to test if it goes through each line (not sure if this is even necessary =\ ). I was wondering if I can see what the httppost
looks like, but it seems like it won't work if I do something like this
Log.w(TAG, httppost);
我得到的错误这一点。
I get errors with that.
任何建议,我怎么能考什么我发送到MySQL进行调试?
Any suggestions as to how I can test what I'm sending out to mysql for debugging?
在此先感谢
推荐答案
根据HttpClient的版本所使用,还有将要开启2关键记录器不同的方式:
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
httpclient.wire.headerhttpclient.wire
在一种类型的客户端,您可以使用Java系统属性来激活相应的记录仪几乎总是使用一个HttpClient的(头&放大器;线材)DEBUG级别的日志记录...
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");
以上不会在所有情况下工作。例如在Android上,我使用
并且,为了激活日志记录WIRE和标题,我不得不重新编译的第三方包,改变类= ch.boye.httpclientandroidlib.androidextra.HttpClientAndroidLog(登录DEBUG ON | OFF)
above will not work in all situations. For example on android, i use the clientand, 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 )
样既记录仪的logcat块打开给什么的HTTP ...
sample block of logcat with both loggers turned on gives complete view of what's happening under the covers of http...
I/PicasaAlbumService( 2218): Starting PHOTOService.onHandleIntent com.b2bpo.media.action.ALBUMLIST
I/ActivityManager( 163): Displayed com.b2bpo.media/.ApplyGeoActivity: +1s349ms (total +5s944ms)
D/dalvikvm( 2218): GC_CONCURRENT freed 292K, 44% free 3625K/6407K, external 387K/519K, paused 2ms+3ms
D/class ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient( 2218): Attempt 1 to execute request
D/class ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection( 2218): Sending request: GET /data/feed/api/user/default?fields=entry%2Ftitle%2Centry%2Fl
ink%5B%40rel%3D%22http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23feed%22%5D&start-index=1&max-results=10&alt=json HTTP/1.1
D/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=json HTTP/1.1
D/ch.boye.httpclientandroidlib.headers( 2218): >> GData-Version: 2
D/ch.boye.httpclientandroidlib.headers( 2218): >> Host: picasaweb.google.com
D/ch.boye.httpclientandroidlib.headers( 2218): >> Connection: Keep-Alive
D/ch.boye.httpclientandroidlib.headers( 2218): >> Authorization: OAuth null
D/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/class ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection( 2218): Receiving response: HTTP/1.1 403 Forbidden
D/ch.boye.httpclientandroidlib.headers( 2218): << HTTP/1.1 403 Forbidden
D/ch.boye.httpclientandroidlib.headers( 2218): << Expires: Fri, 17 Feb 2012 18:07:42 GMT
D/ch.boye.httpclientandroidlib.headers( 2218): << Date: Fri, 17 Feb 2012 18:07:42 GMT
D/ch.boye.httpclientandroidlib.headers( 2218): << Cache-Control: private, max-age=0, must-revalidate
D/ch.boye.httpclientandroidlib.headers( 2218): << Content-Type: text/plain
D/ch.boye.httpclientandroidlib.headers( 2218): << X-Content-Type-Options: nosniff
D/ch.boye.httpclientandroidlib.headers( 2218): << X-Frame-Options: SAMEORIGIN
D/ch.boye.httpclientandroidlib.headers( 2218): << X-XSS-Protection: 1; mode=block
D/ch.boye.httpclientandroidlib.headers( 2218): << Set-Cookie: S=photos_html=UJsnbriEAQZm6J0wEJjfgA; Domain=.google.com; Path=/; Secure; HttpOnly
D/ch.boye.httpclientandroidlib.headers( 2218): << Server: GSE
D/ch.boye.httpclientandroidlib.headers( 2218): << Transfer-Encoding: chunked
D/class ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient( 2218): Connection can be kept alive indefinitely
这篇关于Android的测试HttpPost字符串用于调试目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!