你用错了。 @Named
参数成为url的一部分(如http://server.com/api?source=Java+source+here.
),并且与GET请求具有相同的限制。
您可以将数据封装在pojo中并将其添加为方法参数。例如
@Api(name = "myApi", version = "v1")
public class MyApi {
public static class PseudoCon {
public String foo;
}
public static class SourceContainer {
public String source;
}
@ApiMethod(name = "pseudo", path = "pseudo", httpMethod = HttpMethod.POST)
public PseudoCon getPseudoCode(SourceContainer sourceContainer){
String source = sourceContainer.source;
PseudoCon result = new PseudoCon();
result.foo = source.substring(0, 1);
return result;
}
}
即允许与请求主体的适当POST:
POST http://localhost:8888/_ah/api/myApi/v1/pseudo
{
"source": "Java source here."
}
(源变成在JSON对象封装的)
随着答复
200 OK
{
"foo": "J"
}
“不过GET/POST请求可以处理不超过2KB的数据“你在哪里读过这些数据? (GET请求确实是有限的,因为你只能将数据放入url并且URL有限制 - http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request)。 – zapl
@zapl编辑我的错误,但问题仍然是一个Get请求大于2kB不起作用 –
好吧,那么为什么不使用后? – zapl