blob: 07624d97a9307e760a3458a13880a4494c424ff6 [file] [log] [blame]
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.junit.Test;
public class TestClient {
@Test
public void testPost() throws IOException{
String url = "http://localhost:8080/SRU-WS/";
HttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("query", "rot"));
urlParameters.add(new BasicNameValuePair("maximumRecords", "5"));
urlParameters.add(new BasicNameValuePair("endpoint", "korap"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);
//System.out.println("Sending 'POST' request to URL : " + url);
//System.out.println("Post parameters : " + post.getEntity());
//System.out.println("Response Code : " +
// response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() != 200){
System.out.println("Response Code : " +
response.getStatusLine().getReasonPhrase());
}
}
}