我已经编写了 GAE 云端点 API,并已成功将它们部署到 App Engine。API 在本地以及在 App Engine 上部署后成功运行。
生成云端点后,我尝试在我的 Android 客户端中调用其中一个 API,它会抛出“GoogleJSONResponseException 404 not found”异常。在 API 方法中,我使用 HttpURLConnection 和 JAXB 解组器来调用 URL 并解组 XML 响应。代码如下:
String uri=<some url>;
URL url = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
JAXBContext jc = JAXBContext.newInstance(MyResponse.class);
InputStream xml = connection.getInputStream();
response = (MyResponse) jc.createUnmarshaller().unmarshal(xml);
connection.disconnect();
为什么这仅在尝试使用端点客户端库从 android 客户端调用时不起作用?难道我做错了什么?
注意:我在同一个 android 客户端中调用了另一个 API,它只是将数据插入数据存储区,它工作正常
LogCat 控制台如下所示:
06-17 11:44:49.081: W/System.err(2035): com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
06-17 11:44:49.081: W/System.err(2035): Not Found
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:314)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1060)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
06-17 11:44:49.081: W/System.err(2035): at com.niru.i_collect.RegistrationActivity$FindAddressTask.doInBackground(RegistrationActivity.java:296)
06-17 11:44:49.081: W/System.err(2035): at com.niru.i_collect.RegistrationActivity$FindAddressTask.doInBackground(RegistrationActivity.java:1)
06-17 11:44:49.081: W/System.err(2035): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-17 11:44:49.081: W/System.err(2035): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-17 11:44:49.081: W/System.err(2035): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-17 11:44:49.081: W/System.err(2035): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-17 11:44:49.081: W/System.err(2035): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-17 11:44:49.081: W/System.err(2035): at java.lang.Thread.run(Thread.java:856)