java – 使用Jersey客户端在POST中发送名称值对
发布时间:2020-12-15 04:58:48 所属栏目:Java 来源:网络整理
导读:如何将名称值对作为正文传递给Jersey中的POST ReST服务.使用Apache Commons PostMethod类似于下面的代码 final PostMethod post = new PostMethod(url); post.setRequestBody(new NameValuePair[] { new NameValuePair("loginId",userId),new NameValuePair(
如何将名称值对作为正文传递给Jersey中的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. 解决方法
JAX-RS中有一个
MultivaluedMap接口,在Jersey中有一个’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是如何使用Jersey客户端API的更全面的示例. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |