Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public static void post_example() throws IOException
  2. {
  3. CloseableHttpClient client = HttpClients.createDefault();
  4. HttpPost post = new HttpPost("http://httpbin.org/post");
  5.  
  6. ArrayList<NameValuePair> params = new ArrayList<>();
  7. params.add(new BasicNameValuePair("param-1", "12345"));
  8. params.add(new BasicNameValuePair("param-2", "Hello!"));
  9.  
  10. post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
  11.  
  12. HttpResponse response = client.execute(post);
  13. HttpEntity entity = response.getEntity();
  14.  
  15. entity.writeTo(System.out);
  16.  
  17. client.close();
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement