Creating a UrlEncodedFormEntity from a List of NameValuePairs throws a NullPointerException

后端 未结 2 1641
不知归路
不知归路 2021-02-05 06:39

I\'m creating a unit test to try out the servlet I just created.

@Test
public void test() throws ParseException, IOException {

  HttpClient client = new Defaul         


        
2条回答
  •  孤街浪徒
    2021-02-05 07:11

    Sorry for the stupid question, just solved it by adding the utf-8 format.

    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
    

    Creating a UrlEncodedFormEntity without passing the format will use DEFAULT_CONTENT_CHARSET which is ISO-8859-1

    Which baffles me... what's causing it to throw NullPointerException?

提交回复
热议问题