【发布时间】:2012-04-19 15:52:12
【问题描述】:
我希望使用 RestEasy 框架的仅界面选项,因为它更简洁并且应该可以工作。
但我在 POST 请求中传递参数时遇到问题。
我在文档中找到了这个例子:
@PUT
@Path("basic")
@Consumes("text/plain")
void putBasic(String body);
然后调用:
import org.jboss.resteasy.client.ProxyFactory;
// ...
// this initialization only needs to be done once per VM
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
SimpleClient client = ProxyFactory.create(SimpleClient.class, "http://localhost:8081");
client.putBasic("hello world");
我尝试了以下方法:
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Path("http://localhost:8080/app/resource")
String postBasic(String body);
并被调用:
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
RepoClient client = ProxyFactory.create(RepoClient.class, "");
client.postBasic("hi");
在调用的servelet的doPost方法上打印参数Map(并调试)时,参数为空。我真的看不出我的方法和记录在案的方法(来自这里:Resteasy interface example)之间的区别。
所以总结一下,只使用接口声明和代理实现如何发送POST参数?
解决方案:正如预期的那样...只需使用接收到的参数相应地声明消耗,它就可以工作...问题是在另一个 servlet 中调用 servlet 的 POST 方法。
【问题讨论】: