http://hc.apache.org/httpclient-3.x/tutorial.html
https://docs.google.com/file/d/0B5nZNPW48dpFb1RORnhmblR1OTA/edit?usp=sharing
HttpClient tutorial pdf file
commons-codec.jar
commons-logging.jar
httpclient.jar
httpcore.jar
httpmime.jar
Include in your code:
httpclient.jar
httpcore.jar
Http POST method call using java code:
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://something.com/login");
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("username", "username"));
list.add(new BasicNameValuePair("password", "password"));
httppost.setEntity(new UrlEncodedFormEntity(list));
HttpResponse response = client.execute(httppost);
System.out.println("STATUS LINE: "+response.getStatusLine());
System.out.println("STATUS PHRASE: "+response.getStatusLine().getReasonPhrase());
System.out.println("STATUS METHOD: "+httppost.getMethod());
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println("CONTENT:\n");
InputStream inputStream = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = br.readLine()) != null) {
System.out.println("LINE: "+line);
}
br.close();
}
No comments:
Post a Comment