maven :
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
相关代码:
HttpPost httppost = new HttpPost("http://localadmin/xxxxx");
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("identityNum","xxxxx"));
list.add(new BasicNameValuePair("channel","YT"));
list.add(new BasicNameValuePair("userId","78652109462"));
list.add(new BasicNameValuePair("userName","xxxxx"));
list.add(new BasicNameValuePair("realName","xxxxx"));
UrlEncodedFormEntity entity ;
try {
entity = new UrlEncodedFormEntity(list, "utf-8");
httppost.setEntity(entity);
......
调试发现:
在 super(URLEncodedUtils.format(parameters, charset != null?charset:HTTP.DEF_CONTENT_CHARSET.name()), ContentType.create("application/x-www-form-urlencoded", charset));处报
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.http.client.entity.UrlEncodedFormEntity.toString()
有同学遇到过吗?
调试看看这个类 UrlEncodedFormEntity 在这里引用的时候是不是null
这个空指针就是再调试时报出来的,但该饮用不是null 还可以继续执行下去
我的问题和这个一样,是设置请求头的代码写错了