Java 此 API 不支持解析表单编码的输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19261862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
This API does not support parsing form-encoded input
提问by Shaun
I tried to submit data to an endpoint but it said the data size was too large, so I changed the method to POST and received the error:
我尝试向端点提交数据,但它说数据大小太大,所以我将方法更改为 POST 并收到错误:
This API does not support parsing form-encoded input.
Next I changed the type to application/json, still with post and now I am getting:
接下来我将类型更改为 application/json,仍然使用 post,现在我得到:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
What is the best way to post a large amount of data, i.e. 2730 bytes to an endpoint and have it handle it properly? In my case the field in question is of type Text as I am over the 500 character limit for app engine to hold in a String.
将大量数据(即 2730 字节)发布到端点并让它正确处理的最佳方法是什么?在我的情况下,有问题的字段是文本类型,因为我超过了应用引擎在字符串中保存的 500 个字符的限制。
Also, as with many things, this works great on my local machine, it only gives this error on the live app engine instance.
此外,与许多事情一样,这在我的本地机器上运行良好,它只会在实时应用引擎实例上出现此错误。
Thanks!
谢谢!
回答by Greg
Not sure if your problem is related, but I received the "This API does not support parsing form-encoded input." error when I was attempting to use curl to send a POST message like this:
不确定您的问题是否相关,但我收到“此 API 不支持解析表单编码输入”。当我尝试使用 curl 发送这样的 POST 消息时出错:
curl -X POST -d '{"name": "Foo"}' http://foo.appspot.com/_ah/api/foo/1/endpoint
The problem was that I was not setting the content type. curl POSTs with Content-Type: application/x-www-form-urlencoded if it's not specified on the command line. Google cloud endpoints don't accept this content type.
问题是我没有设置内容类型。如果未在命令行中指定,则使用 Content-Type: application/x-www-form-urlencoded 卷曲 POST。Google 云端点不接受此内容类型。
When I changed the curl invocation to include the content type, it worked:
当我更改 curl 调用以包含内容类型时,它起作用了:
curl -X POST -d '{"name": "Foo"}' --header "Content-Type: application/json" http://foo.appspot.com/_ah/api/foo/1/endpoint