我在AppEngine中有以下方法:
@ApiMethod(name = "authed", path = "greeting/authed")
public HelloGreeting authedGreeting(User user) {
...
}
我在Android AsyncTask中的doInBackground方法:
HelloGreeting hg = null;
try {
hg = service.authed().execute();
} catch (IOException e) {
Log.d("error", e.getMessage(), e);
}
return hg;
我遇到了ff错误:
/_ah/api/.../v1/greeting/authed: java.io.EOFException
在logcat中:
Problem accessing /_ah/api/.../v1/greeting/authed. Reason: INTERNAL_SERVER_ERROR
at java.util.zip.GZIPInputStream.readUByte
at java.util.zip.GZIPInputStream.readUShort
at java.util.zip.GZIPInputStream.readUShort
仅在调用非auth方法时才有效。如何解决?
我正在使用本地服务器。
答案 0 :(得分:7)
我在调用插入值时遇到了类似的问题。我有点不同,因为我没有使用身份验证,但是我得到了同样的例外。我正在使用 appengine-java-sdk-1.8.8 。我能够使其他端点调用出现此错误。我查看了生成的代码,我看到的工作调用与非工作调用之间的差异是HttpMethod。失败的呼叫被定义为"POST"
。我可以使用httpMethod=ApiMethod.HttpMethod.GET
注释中的注释属性@ApiMethod
来更改此内容。
@ApiMethod(httpMethod = ApiMethod.HttpMethod.GET, name = "insertUserArtist", path = "insertUserArtist")
然后我重新生成了客户端代码,我能够在没有获得可怕的EOFException
的情况下进行调用。我不确定为什么POST不能正常工作但将其更改为GET工作。这可能会提出一些关于可以发送多少数据并且应该解决的问题(可能是库问题)。我将研究创建一个提交给Google的演示应用程序。
答案 1 :(得分:0)
如果您传递了“实体”对象,则POST将起作用。如果您正在传递原始数据类型,那么您将无法使用HttpMethod.GET。
答案 2 :(得分:0)
如果您在本地开发服务器上运行, 然后在MyApi.Builder中添加以下代码段,以便在设置根URL后正确设置它。
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
})
来源:https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints