我启动并运行了我的 android+appengine 应用程序(端点),在我的本地机器上一切正常,所以我决定上传我的 appengine 代码,以便我可以尝试直接在手机上通过 Android 应用程序访问数据。
当我尝试调用我的 appengine 后端时,出现 404 错误。
在浏览器上,如果我尝试调用 http://[myAppID].appspot.com/_ah/spi 我得到:
Error: HTTP method GET is not supported by this URL
所以主要的 serlvet 正在响应,我做错了什么?
(授予互联网许可!)
提前致谢!!
这是代码,这是在 AsyncTask 中执行的:
Builder endpointBuilder = new Myendpoint.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) {
}
});
Myendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
try {
MyUsers result = endpoint.searchMyUser(params[0]).execute();
return result.getItems().get(0);
} catch (Exception e) {
e.printStackTrace();
return null;
}
这是 CloudEnpointUtils 中的代码(显然 LOCAL_ANDROID_RUN 设置为 false):
public static <B extends GoogleClient.Builder> B updateBuilder(B builder) {
if (LOCAL_ANDROID_RUN) {
builder.setRootUrl(LOCAL_APP_ENGINE_SERVER_URL + "/_ah/api/");
}
// only enable GZip when connecting to remote server
final boolean enableGZip = builder.getRootUrl().startsWith("https:");
builder.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
public void initialize(JsonHttpRequest jsonHttpRequest) {
jsonHttpRequest.setEnableGZipContent(enableGZip);
}
});
return builder;
}
我为错误添加了 logcat:
10-04 11:40:22.770 W/System.err(13564): com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
10-04 11:40:22.770 W/System.err(13564): Not Found
10-04 11:40:22.775 W/System.err(13564): at com.google.api.client.googleapis.services.GoogleClient.executeUnparsed(GoogleClient.java:279)
10-04 11:40:22.775 W/System.err(13564): at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:207)
10-04 11:40:22.775 W/System.err(13564): at com.appspot.api.services.myuserendpoint.Myuserendpoint$SearchMyUser.execute(Myuserendpoint.java:702)
10-04 11:40:22.775 W/System.err(13564): at it.my.my.app.core.MyBusinessDelegate$MyUserGetter.doInBackground(MyBusinessDelegate.java:303)
10-04 11:40:22.775 W/System.err(13564): at it.my.my.app.core.MyBusinessDelegate$MyUserGetter.doInBackground(MyBusinessDelegate.java:1)
10-04 11:40:22.780 W/System.err(13564): at android.os.AsyncTask$2.call(AsyncTask.java:264)
10-04 11:40:22.780 W/System.err(13564): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-04 11:40:22.780 W/System.err(13564): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-04 11:40:22.780 W/System.err(13564): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
10-04 11:40:22.785 W/System.err(13564): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-04 11:40:22.785 W/System.err(13564): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-04 11:40:22.785 W/System.err(13564): at java.lang.Thread.run(Thread.java:856)
编辑:AppEngine 部署日志
------------ Deploying frontend ------------
Preparing to deploy:
Created staging directory at: 'C:\Users\XXXXXXXXX\AppData\Local\Temp\appcfg1884750854541661749.tmp'
Scanning for jsp files.
Compiling jsp files.
Scanning files on local disk.
Initiating update.
Cloning 1 static files.
Cloning 66 application files.
Deploying:
Uploading 0 files.
Initializing precompilation...
Deploying new version.
Verifying availability:
Will check again in 1 seconds.
Will check again in 2 seconds.
Will check again in 4 seconds.
Closing update: new version is ready to start serving.
Updating datastore:
Uploading index definitions.
Deployment completed successfully
EDIT2:其他信息
我尝试与我在 appengine 战争中放入的 java servlet 通信,通过浏览器没有问题,一切正常,如果我尝试从命令行 ping 或尝试以编程方式通信,我有这个错误:
"Unable to resolve host "[myappID].appspot.com": No address associated with hostname"
请任何人帮我找到解决方案
编辑 3:好消息,我已经能够使用 appengine 地址调用我的 servlet,其版本为:
http://[version].[myAppID].appspot.com/myServlet
代替:
http://[myAppID].appspot.com/myServlet
我不知道为什么,但这样就可以了!即使使用版本地址技巧,尝试通过端点调用远程 appengine 应用程序仍然没有运气,希望对您有所帮助!