使用Jersey客户端在POST中发送名称值对 [英] Sending Name Value Pair in POST using Jersey Client

查看:130
本文介绍了使用Jersey客户端在POST中发送名称值对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将名称值对作为正文传递给泽西岛的POST ReST服务.类似于下面使用Apache Commons PostMethod的代码

How can i pass name value pairs as body to a POST ReST Service in Jersey. Something similar to the code below using 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.在我的应用程序中,我使用了泽西岛.所以我想使用球衣类/功能而不是Apache.

I'm porting this call to my application. The current call uses apache commons PostMethod. In my application i used Jersey. So i want to use the jersey classes/features instead of apache.

推荐答案

有一个 MultivaluedMap 接口,泽西岛中有一个'MultivaluedMapImpl'.

There is a MultivaluedMap interface in JAX-RS with a 'MultivaluedMapImpl' in Jersey.

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);

此处是如何使用Jersey客户端API的更全面的示例.

Here is a more comprehensive example of how to use Jersey client API.

这篇关于使用Jersey客户端在POST中发送名称值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆