Please help.
package com.codegym.task.task40.task4002;
import org.apache.http.*;
import org.apache.http.entity.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.HttpClientBuilder;
import java.io.*;
import java.nio.charset.Charset;
import java.util.List;
import java.net.*;
public class Solution {
public static void main(String[] args) throws Exception {
Solution solution = new Solution();
solution.sendPost("http://requestb.in/1h4qhvv1",
"name=zapp&mood=good&locale=&id=777");
}
public void sendPost(String url, String urlParameters) throws Exception {
HttpClient client = getHttpClient();
HttpPost request = new HttpPost(url);
request.addHeader("User-Agent", "Mozilla/5.0");
// Create output stream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Create the request
HttpEntity e = new ByteArrayEntity(urlParameters.getBytes());
e.writeTo(outputStream);
request.setEntity(e);
// Send the request
HttpResponse response = client.execute(request);
System.out.println("Response Code: "+response.getStatusLine().getStatusCode());
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String responseLine;
while ((responseLine = bufferedReader.readLine()) != null) {
result.append(responseLine);
}
System.out.println("Response: " + result.toString());
}
protected HttpClient getHttpClient() {
return HttpClientBuilder.create().build();
}
}