margaretha | c8f57d9 | 2014-04-28 12:13:12 +0000 | [diff] [blame^] | 1 | import java.io.IOException; |
| 2 | import java.io.UnsupportedEncodingException; |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import org.apache.http.HttpResponse; |
| 7 | import org.apache.http.NameValuePair; |
| 8 | import org.apache.http.client.ClientProtocolException; |
| 9 | import org.apache.http.client.HttpClient; |
| 10 | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| 11 | import org.apache.http.client.methods.HttpPost; |
| 12 | import org.apache.http.impl.client.HttpClients; |
| 13 | import org.apache.http.message.BasicNameValuePair; |
| 14 | import org.junit.Test; |
| 15 | |
| 16 | |
| 17 | public 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 | } |