我如何将名称值对作为正文传递给泽西岛的 POST ReST 服务。类似于下面使用 Apache Commons PostMethod 的代码
final PostMethod post = new PostMethod(url);
post.setRequestBody(new NameValuePair[] {
new NameValuePair("loginId", userId),
new NameValuePair("logonPassword", password),
new NameValuePair("signature", signature),
new NameValuePair("timestamp", timestamp),
new NameValuePair("sourceSiteId", sourceSiteId) });
我正在将此调用移植到我的应用程序中。当前调用使用apache commons PostMethod。在我的应用程序中,我使用了泽西岛。所以我想使用 jersey 类/功能而不是 apache。
有一个多值映射 http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/MultivaluedMap.html接口在JAX-RS
在泽西岛有一个“MultivaluedMapImpl”。
Client client = Client.create();
WebResource webResource = client.resource("http://site.com/resource");
MultivaluedMap<String, String> map = new MultivaluedMapImpl();
map.put("loginId", loginId);
...
ClientResponse response = webResource.type("application/x-www-form-urlencoded")
.post(ClientResponse.class, map);
Here https://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with是如何使用 Jersey 客户端 API 的更全面的示例。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)