小编stu*_*ain的帖子

如何查看从httppost发送的字符串?

下面是一段试图发布到本地服务器上的PHP脚本的代码片段.我正在将数据传回服务器的MySQL表,因为数据量非常小,我想我会使用HttpClient将数据嵌入到URL参数中.

但是,即使我从服务器获得的响应是​​正常的(HTTP代码= 200),很明显服务器端PHP脚本没有获得正确格式化的数据(对MySQL表没有影响).但是,当我在浏览器中手动输入URL + args时,如下所示:

http://10.0.0.13/jobs_returndata_test.php?jobnum=189193&pnum=3&entime=13:00&extime=14:00 
Run Code Online (Sandbox Code Playgroud)

例如,一切正常(PHP脚本正确写入MySQL表).

我的问题:我有没有办法真正查看HttpClient发送的内容?(即HttpPost对象的整个.toString内容?).这是Android端代码段:

// Create a new HttpClient and Post Header, send data as args to PHP file
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.0.13/jobs_returndata.php");
try {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("jobnum",convertSimple(jobNum)));
    nameValuePairs.add(new BasicNameValuePair("pnum",convertSimple(rowNum)));
    nameValuePairs.add(new BasicNameValuePair("entime",enteredInTime));
    nameValuePairs.add(new BasicNameValuePair("extime",enteredOutTime));

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    Log.i("HTTP Post", "Execute Post sending jobnum="+ convertSimple(jobNum) +      
    "&pnum="+ convertSimple(rowNum) + "&entime=" + enteredInTime
                    + "&extime=" + enteredOutTime);
    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);
    Log.i("HTTP Post", "Response …
Run Code Online (Sandbox Code Playgroud)

string url android httpclient http-post

2
推荐指数
1
解决办法
4643
查看次数

标签 统计

android ×1

http-post ×1

httpclient ×1

string ×1

url ×1