jersey client 发送Post请求 【带参数】
2010-05-31 23:15
267 查看
@Path("postUser") public class PostUser { @POST @Produces(MediaType.TEXT_XML) public String postUser(){ return "涛哥"; } @Path("bean") @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON}) public User postUser(@FormParam("username") String username){ User user = new User(); System.out.println(username); user.setUsername(username); user.setPassword("涛哥"); return user; } }
public class PostUser { /** * @param args * @throws UnsupportedEncodingException */ public static void main(String[] args) throws UnsupportedEncodingException { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(getBaseURI()); MultivaluedMap<String, String> param = new MultivaluedMapImpl(); param.add("username", "ssss"); System.out.println(service.path("services").path("postUser") .path("bean").queryParams(param) .type(MediaType.APPLICATION_FORM_URLENCODED).post(String.class)); } private static URI getBaseURI() { return UriBuilder.fromUri( "http://localhost:8080/jersey/").build(); }
// 注意 .type(MediaType.APPLICATION_FORM_URLENCODED).
type 而不是 accept 否则将出错的
相关文章推荐
- 如何使用火狐下的两款接口测试工具RESTClient和HttpRequester发送post请求
- postman发送post请求,用request.getParameter()获取请求参数注意事项
- httpclient发送不带参数post数据
- HttpClient 的GET(带参数)、POST请求方式,工具类方法
- Httpclient发送POST请求
- HttpClient4.X发送带参数的Get请求
- HttpClient发送Post请求(二)
- httpclient发送无参数的post数据
- java 接受和发送http,post,get请求,参数中文乱码解决。
- Vue 使用axios 发送post请求,参数格式有错误问题
- httpClient 发送 post请求 json数据
- java 利用httpclient 3.1 和 httpclient4.1.2发送post请求
- android_30_使用HttpClient发送Get和Post请求
- httpclient4 post请求传参数
- 以post方式携窗体等参数向服务器发送请求 发出去的字节流 返回的内容
- HttpUrlConnection用get和post请求发送参数
- Android发送GET和POST以及HttpClient发送POST请求给服务器响应
- [置顶] android网络通讯之HttpClient4不指定参数名发送Post
- 火狐浏览器使用RESTClient发送post请求方法
- HttpClient发送get post请求和数据解析