gpt4 book ai didi

java - android 测试 HttpPost 字符串以进行调试

转载 作者:行者123 更新时间:2023-12-01 15:22:59 25 4
gpt4 key购买 nike

我正在尝试使用 HttpPost 将数据从手机发送到 mysql,但我没有设置任何服务器,所以我想知道我是否可以准确地看到我发送的内容以及它的样子。我对 JSON 以及它们的外观有点熟悉。所以我很好奇我将向 mysql 发送什么以进行调试。

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 的样子,但如果我这样做,它似乎不会工作

Log.w(TAG, httppost);

我遇到了错误。

关于如何测试我发送到 mysql 进行调试的内容有什么建议吗?

提前致谢

最佳答案

根据您使用的 httpclient 版本,可以通过多种方式打开 2 个关键记录器:

httpclient.wire.headerhttpclient.wire

在一种类型的客户端中,您可以使用 java 系统属性来激活几乎总是由 HttpClient 使用的相应记录器上的调试级别日志记录( header 和线路)...

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

以上方法并不适用于所有情况。例如在android上,我使用client并且,为了激活 WIRE 和 HEADERS 的日志记录,我必须重新编译第 3 方包,更改 class= ch.boye.httpclientandroidlib.androidextra.HttpClientAndroidLog ( Log DEBUG ON | OFF )

两个记录器都打开的 logcat 示例 block 提供了 http 背后发生的事情的完整 View ...

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

关于java - android 测试 HttpPost 字符串以进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10594470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com