blob: 07624d97a9307e760a3458a13880a4494c424ff6 [file] [log] [blame]
margarethac8f57d92014-04-28 12:13:12 +00001import java.io.IOException;
2import java.io.UnsupportedEncodingException;
3import java.util.ArrayList;
4import java.util.List;
5
6import org.apache.http.HttpResponse;
7import org.apache.http.NameValuePair;
8import org.apache.http.client.ClientProtocolException;
9import org.apache.http.client.HttpClient;
10import org.apache.http.client.entity.UrlEncodedFormEntity;
11import org.apache.http.client.methods.HttpPost;
12import org.apache.http.impl.client.HttpClients;
13import org.apache.http.message.BasicNameValuePair;
14import org.junit.Test;
15
16
17public class TestClient {
18
19 @Test
20 public void testPost() throws IOException{
21 String url = "http://localhost:8080/SRU-WS/";
22 HttpClient client = HttpClients.createDefault();
23 HttpPost post = new HttpPost(url);
24
25 List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
26 urlParameters.add(new BasicNameValuePair("query", "rot"));
27 urlParameters.add(new BasicNameValuePair("maximumRecords", "5"));
28 urlParameters.add(new BasicNameValuePair("endpoint", "korap"));
29 post.setEntity(new UrlEncodedFormEntity(urlParameters));
30
31 HttpResponse response = client.execute(post);
32 //System.out.println("Sending 'POST' request to URL : " + url);
33 //System.out.println("Post parameters : " + post.getEntity());
34 //System.out.println("Response Code : " +
35 // response.getStatusLine().getStatusCode());
36 if (response.getStatusLine().getStatusCode() != 200){
37 System.out.println("Response Code : " +
38 response.getStatusLine().getReasonPhrase());
39 }
40
41 }
42}