【发布时间】:2014-02-23 08:17:25
【问题描述】:
我正在尝试我的第一个 GAE 服务器和 Android 连接。我正在通过我的计算机(192.168.1.24)上的 Android ADT 运行 GAE 服务器。我的 Android 设备通过 USB 以开发者模式连接。我正在尝试从设备发出 HTTP 请求并存储响应。但我收到以下错误。
02-23 03:10:22.915: E/AndroidRuntime(18076): FATAL EXCEPTION: main
02-23 03:10:22.915: E/AndroidRuntime(18076): java.lang.IllegalStateException: Could not execute method of the activity
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View$1.onClick(View.java:3838)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View.performClick(View.java:4475)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View$PerformClick.run(View.java:18796)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.os.Handler.handleCallback(Handler.java:730)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.os.Handler.dispatchMessage(Handler.java:92)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.os.Looper.loop(Looper.java:137)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.app.ActivityThread.main(ActivityThread.java:5455)
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invoke(Method.java:525)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
02-23 03:10:22.915: E/AndroidRuntime(18076): at dalvik.system.NativeStart.main(Native Method)
02-23 03:10:22.915: E/AndroidRuntime(18076): Caused by: java.lang.reflect.InvocationTargetException
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invoke(Method.java:525)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View$1.onClick(View.java:3833)
02-23 03:10:22.915: E/AndroidRuntime(18076): ... 11 more
02-23 03:10:22.915: E/AndroidRuntime(18076): Caused by: java.lang.IllegalArgumentException: Illegal character in scheme at index 0: 192.168.1.24:8889/myserver?username=qwerty&password=qwerty
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.net.URI.create(URI.java:727)
02-23 03:10:22.915: E/AndroidRuntime(18076): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
02-23 03:10:22.915: E/AndroidRuntime(18076): at httprequest.GetMethods.doGetWithResponse(GetMethods.java:28)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.example.tandemstory.UserAuth.doAuth(UserAuth.java:24)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.example.tandemstory.SignIn.onSignin(SignIn.java:74)
02-23 03:10:22.915: E/AndroidRuntime(18076): ... 14 more
从Android设备发起http请求的语句如下。
String alias=UserAuth.doAuth(username, password);
UserAuth.doAuth() 如下
public static String doAuth(String username,String password) {
// CONSTRUCT GET REQUEST URL
String url = "192.168.1.24/myserver?username=qwerty&password=qwerty"
// XML RESPONSE AS A STRING GETS RETURNED
String response = GetMethods.doGetWithResponse(URL_BASE, httpClient);
return response;
}
GetMethods.doGetWithResponse() 如下
public static String doGetWithResponse(String mUrl,DefaultHttpClient httpClient){
String ret=null;
HttpResponse response=null;
//initiate get method with username and password
HttpGet getMethod=new HttpGet(mUrl);
try{
//use http client to execute method
response=httpClient.execute(getMethod);
if(response!=null){
//convert http response to string
ret=getResponseBody(response);
}
}catch(Exception e){
e.printStackTrace();
}
return ret;
}
请指点解决方法。
【问题讨论】:
-
我已经完成/尝试过的事情 - (1) 在我的服务器运行配置的参数选项卡中添加了 --address=192.168.1.24。我可以从我的计算机使用此 IP 地址访问服务器。但无法从我设备的浏览器(在调试模式下通过 USB 连接)访问它。 (2) 在我的电脑上禁用了防火墙。
-
我以前试过这个,但没有成功。我知道的唯一方法是使用与 gae 服务器在同一台机器上运行的 android 模拟器,并在 android 中使用 10.0.2.2 作为 localhost
标签: android eclipse google-app-engine adt