带有参数的Java post请求

时间:2018-03-23 10:55:03

标签: java apache

我看到lin通过POST方法发送带有特定参数的邀请,在firefox开发人员工具中看起来像:

enter image description here

我通常使用Apache HttpClient通过JAVA发送请求,所以如果需要参数,只需输入:

HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("sn", "C02G8416DRJM"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);

但我可能不明白这棵树是什么&#39;结构意味着如何实现它。

你能建议我怎么做吗?

1 个答案:

答案 0 :(得分:0)

我不知道LinkedIn在做什么,但对我来说这看起来像是一个JSON字符串的POST。这是纯数据,而不是url-form编码的键值对。通常你把它作为一个普通的字符串发送:

post.setEntity(new StringEntity("Hello, World"));
相关问题