有没有办法通过eclipse中的android应用程序调试http请求? [英] is there a way to debug a http request through an android app inside eclipse?

查看:152
本文介绍了有没有办法通过eclipse中的android应用程序调试http请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题自己说,但我会尽量澄清。通过应用程序发送我的http请求以连接本地数据库

  JSONObject json = jsonParser.makeHttpRequest(urlCreate,
POST,params);

json的返回值为null;这会造成致命的错误,导致我的应用程序崩溃,并且不会通过请求向我反馈关于错误的位置或位置。我认为这个错误是在使用urlCreate参数调用的php文件中的,所以当通过android应用程序调用eclipse之前,如何跟踪和调试php文件?

解决方案

找到我自己的答案:是的,有办法做到这一点。



在你的解析器(Json解析器在我的情况下,在JSonparser.java中定义),默认情况下,您可能会有以下代码:

  DefaultHttpClient httpClient = new DefaultHttpClient(); 
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();

您可以看到这里是http请求的位置(在这种情况下是一个帖子)。现在你需要做的是在这些行创建一个logcat反馈之后,响应反馈更具体:

  String all = EntityUtils.toString(httpEntity); 
Log.d(Response,all);

现在,打开logcat [Window - > Show View - > Other - > Android - > Logcat]并在plus按钮上添加一个新的过滤器。在屏幕上会弹出类型任何你想要的过滤器名称(在我的情况下,你可以看到它已经响应)和标签给你在$ code> Log.d(响应所有); 。





运行应用程序,您会看到当您调用与数据库的连接时,会导致错误的一些php移动(如连接请求)会在这个过滤器中出现。例如,我收到的最后一个错误日志是:

  03-23 14:26:06.611:D / Response(1270) < br /> 
03-23 14:26:06.611:D / Response(1270):< font size ='1'>< table class ='xdebug-error xe-warning'dir ='ltr'border = '1'cellspacing ='0'cellpadding ='1'>
03-23 14:26:06.611:D / Response(1270):< tr>< th align ='left'bgcolor ='#f57900'colspan =5>< span style = 'background-color:#cc0000;颜色:#fce94f; font-size:x-large;'>(!)< / span>警告:mysql_connect():访问被拒绝用户'root'@'localhost'(使用密码:是)在C:\wamp\www\android_connect\db_connect.php行< i> 28< i> ;< / th>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< th align ='left'bgcolor ='#e9b96e'colspan ='5'>调用堆栈< / th& ;< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< th align ='center'bgcolor ='#eeeeec'>#< / th>< th align ='left'bgcolor ='#eeeeec'> Time< / th>< th align ='left'bgcolor ='#eeeeec'> Memory< / th>< th align ='left'bgcolor ='# eeeeec'>功能< / th>< th align ='left'bgcolor ='#eeeeec'>位置< / th>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 1< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0003< / td>< td bgcolor ='#eeeeec'align ='right'> 143616< / td>< td bgcolor ='#eeeeec'> main}()< / td>< td title ='C:\wamp\www\android_connect\create_product.php'bgcolor ='#eeeeec'> .. \create_product.php< b> :< / b> 0< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 2< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0006< / td>< td bgcolor ='#eeeeec'align ='right'> 150200< / td>< td bgcolor ='#eeeeec'> DB_CONNECT - > __ construct()< / td>< td title ='C:\wamp\www\android_connect\create_product.php'bgcolor ='#eeeeec'> .. \create_product.php< b>:< / b> 20< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 3< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0006< / td>< td bgcolor ='#eeeeec'align ='right'> 150216< / td>< td bgcolor ='#eeeeec'> DB_CONNECT - > connect()< / td>< td title ='C:\wamp\www\android_connect\db_connect.php'bgcolor ='#eeeeec'> .. \db_connect.php< b>:< / b> 11< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 4< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0008< / td>< td bgcolor ='#eeeeec'align ='right'> 150832< / td>< td bgcolor ='#eeeeec'>< ; href ='http://www.php.net/function.mysql-connect'target ='_ new'> mysql_connect< / a>
03-23 14:26:06.611:D / Response(1270):()< / td>< td title ='C:\wamp\www\android_connect\db_connect.php' bgcolor ='#eeeeec'> .. \db_connect.php< b>:< / b> 28< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< / table>< / font>
03-23 14:26:06.611:D / Response(1270):访问被拒绝用户'root'@'localhost'(使用密码:YES)< br />
03-23 14:26:06.611:D / Response(1270):< font size ='1'>< table class ='xdebug-error xe-warning'dir ='ltr'border = '1'cellspacing ='0'cellpadding ='1'>
03-23 14:26:06.611:D / Response(1270):< tr>< th align ='left'bgcolor ='#f57900'colspan =5>< span style = 'background-color:#cc0000;颜色:#fce94f; font-size:x-large;'>(!)< / span>警告:mysql_close():没有在C:\wamp\www\android_connect\db_connect.php中提供的MySQL-Link资源在< i> 42< / th>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< th align ='left'bgcolor ='#e9b96e'colspan ='5'>调用堆栈< / th& ;< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< th align ='center'bgcolor ='#eeeeec'>#< / th>< th align ='left'bgcolor ='#eeeeec'> Time< / th>< th align ='left'bgcolor ='#eeeeec'> Memory< / th>< th align ='left'bgcolor ='# eeeeec'>功能< / th>< th align ='left'bgcolor ='#eeeeec'>位置< / th>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 1< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0003< / td>< td bgcolor ='#eeeeec'align ='right'> 143616< / td>< td bgcolor ='#eeeeec'> main}()< / td>< td title ='C:\wamp\www\android_connect\create_product.php'bgcolor ='#eeeeec'> .. \create_product.php< b> :< / b> 0< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 2< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0006< / td>< td bgcolor ='#eeeeec'align ='right'> 150200< / td>< td bgcolor ='#eeeeec'> DB_CONNECT - > __ construct()< / td>< td title ='C:\wamp\www\android_connect\create_product.php'bgcolor ='#eeeeec'> .. \create_product.php< b>:< / b> 20< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 3< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0006< / td>< td bgcolor ='#eeeeec'align ='right'> 150216< / td>< td bgcolor ='#eeeeec'> DB_CONNECT - > connect()< / td>< td title ='C:\wamp\www\android_connect\db_connect.php'bgcolor ='#eeeeec'> .. \db_connect.php< b>:< / b> 11< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 4< / td>< td bgcolor = '#eeeeec'align ='center'> 0.0110< / td>< td bgcolor ='#eeeeec'align ='right'> 146960< / td>< td bgcolor ='#eeeeec'> DB_CONNECT - > __ destruct()< / td>< td title ='C:\wamp\www\android_connect\db_connect.php'bgcolor ='#eeeeec'> .. \db_connect.php< b>:< / b> 0< / td>< / tr>
03-23 14:26:06.611:D / Response(1270):< tr>< td bgcolor ='#eeeeec'align ='center'> 5< / td>< td bgco

一个提示是导出并将此日志保存为一个html文件,以更好地了解发生的情况



干杯。




The question speaks for itself but I will try to clarify more. after make my http request through the app to connect a local databse

JSONObject json = jsonParser.makeHttpRequest(urlCreate,
                        "POST", params);

the return of json is being null; this throws a fatal error, crashs my app and it doesnt feeds me back about where or what exactly is the error through the request. I think the error is inside the php file being called with the "urlCreate" parameter, so how can I track and debug the php file inside eclipse when its being called through an android app?

解决方案

Found my own answer: Yes, there is a way to do this.

Inside your parser (Json parser in my case which was defined inside JSonparser.java), as default, you are probably going to have this code:

 DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();

As you can see here is where you http request is made (in this case a post one). Now what you need to do is after those lines create one logcat feedback, a response feedback to be more specific:

String all=EntityUtils.toString(httpEntity);
                Log.d("Response",all);

Now, open the logcat [ Window -> Show View -> Other -> Android -> Logcat] and add a new filter on the plus button. On the screen thats gonna pop up type Anything you want as Filter name (in my case as u can see its already Response) and as Tag give the same name u gave at Log.d("Response",all);.

Run you application and you will see that when you call the connection with the database, some php moves that can cause errors (such as connection request) will come up in this filter. For example the last error log I received was:

03-23 14:26:06.611: D/Response(1270): <br />
03-23 14:26:06.611: D/Response(1270): <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
03-23 14:26:06.611: D/Response(1270): <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp\www\android_connect\db_connect.php on line <i>28</i></th></tr>
03-23 14:26:06.611: D/Response(1270): <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
03-23 14:26:06.611: D/Response(1270): <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>143616</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\android_connect\create_product.php' bgcolor='#eeeeec'>..\create_product.php<b>:</b>0</td></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>150200</td><td bgcolor='#eeeeec'>DB_CONNECT->__construct(  )</td><td title='C:\wamp\www\android_connect\create_product.php' bgcolor='#eeeeec'>..\create_product.php<b>:</b>20</td></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>150216</td><td bgcolor='#eeeeec'>DB_CONNECT->connect(  )</td><td title='C:\wamp\www\android_connect\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>11</td></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.0008</td><td bgcolor='#eeeeec' align='right'>150832</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mysql-connect' target='_new'>mysql_connect</a>
03-23 14:26:06.611: D/Response(1270): (  )</td><td title='C:\wamp\www\android_connect\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>28</td></tr>
03-23 14:26:06.611: D/Response(1270): </table></font>
03-23 14:26:06.611: D/Response(1270): Access denied for user 'root'@'localhost' (using password: YES)<br />
03-23 14:26:06.611: D/Response(1270): <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
03-23 14:26:06.611: D/Response(1270): <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: mysql_close(): no MySQL-Link resource supplied in C:\wamp\www\android_connect\db_connect.php on line <i>42</i></th></tr>
03-23 14:26:06.611: D/Response(1270): <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
03-23 14:26:06.611: D/Response(1270): <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>143616</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\android_connect\create_product.php' bgcolor='#eeeeec'>..\create_product.php<b>:</b>0</td></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>150200</td><td bgcolor='#eeeeec'>DB_CONNECT->__construct(  )</td><td title='C:\wamp\www\android_connect\create_product.php' bgcolor='#eeeeec'>..\create_product.php<b>:</b>20</td></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>150216</td><td bgcolor='#eeeeec'>DB_CONNECT->connect(  )</td><td title='C:\wamp\www\android_connect\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>11</td></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.0110</td><td bgcolor='#eeeeec' align='right'>146960</td><td bgcolor='#eeeeec'>DB_CONNECT->__destruct(  )</td><td title='C:\wamp\www\android_connect\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>0</td></tr>
03-23 14:26:06.611: D/Response(1270): <tr><td bgcolor='#eeeeec' align='center'>5</td><td bgco

One tip is to export and save this log as one html file to get a better view of whats going on.

Cheers.

这篇关于有没有办法通过eclipse中的android应用程序调试http请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆