0

我正在开发一个 android 项目,当我尝试使用 php 文件和 easyphp/mySQL 登录应用程序时,它失败了,这是 logcat 错误:

    08-03 04:53:20.203: W/System.err(244): org.apache.http.NoHttpResponseException: The     target server failed to respond
    08-03 04:53:20.237: W/System.err(244):  at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:85)
    08-03 04:53:20.247: W/System.err(244):  at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
    08-03 04:53:20.247: W/System.err(244):  at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:179)
    08-03 04:53:20.247: W/System.err(244):  at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
    08-03 04:53:20.260: W/System.err(244):  at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
    08-03 04:53:20.260: W/System.err(244):  at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
    08-03 04:53:20.260: W/System.err(244):  at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
    08-03 04:53:20.282: W/System.err(244):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:410)
    08-03 04:53:20.288: W/System.err(244):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    08-03 04:53:20.300: W/System.err(244):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    08-03 04:53:20.307: W/System.err(244):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    08-03 04:53:20.320: W/System.err(244):  at com.stage.sondage.Login.onClick(Login.java:109)
    08-03 04:53:20.320: W/System.err(244):  at android.view.View.performClick(View.java:2364)
    08-03 04:53:20.339: W/System.err(244):  at android.view.View.onTouchEvent(View.java:4179)
    08-03 04:53:20.358: W/System.err(244):  at android.widget.TextView.onTouchEvent(TextView.java:6540)
    08-03 04:53:20.358: W/System.err(244):  at android.view.View.dispatchTouchEvent(View.java:3709)
    08-03 04:53:20.367: W/System.err(244):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    08-03 04:53:20.379: W/System.err(244):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    08-03 04:53:20.387: W/System.err(244):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    08-03 04:53:20.401: W/System.err(244):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    08-03 04:53:20.401: W/System.err(244):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    08-03 04:53:20.401: W/System.err(244):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    08-03 04:53:20.407: W/System.err(244):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
    08-03 04:53:20.420: W/System.err(244):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
    08-03 04:53:20.420: W/System.err(244):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
    08-03 04:53:20.420: W/System.err(244):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
    08-03 04:53:20.420: W/System.err(244):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
    08-03 04:53:20.427: W/System.err(244):  at android.os.Handler.dispatchMessage(Handler.java:99)
    08-03 04:53:20.438: W/System.err(244):  at android.os.Looper.loop(Looper.java:123)
    08-03 04:53:20.459: W/System.err(244):  at android.app.ActivityThread.main(ActivityThread.java:4363)
    08-03 04:53:20.459: W/System.err(244):  at java.lang.reflect.Method.invokeNative(Native Method)
    08-03 04:53:20.459: W/System.err(244):  at java.lang.reflect.Method.invoke(Method.java:521)
    08-03 04:53:20.459: W/System.err(244):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    08-03 04:53:20.467: W/System.err(244):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    08-03 04:53:20.517: W/System.err(244):  at dalvik.system.NativeStart.main(Native Method)

登录中的第 109 行是response = hhtpclient.execute(httppost);

其中 response 是 HttpResponse 的一个实例;我已经尝试了这两个值

httppost=new HttpPost("http://10.0.2.2/android/connection.php"); 

httppost=new HttpPost("http://127.0.1.1/android/connection.php"); 

(顺便问一下这两个IP地址有什么区别?)

谢谢,

4

1 回答 1

1

您的清单文件中的 Internet 权限是必需的。

<uses-permission android:name="android.permission.INTERNET"/> 

将此粘贴到应用程序标记后的清单文件中。

于 2012-08-03T05:16:58.577 回答