Friday, October 28, 2011

Creating HTTP or HTTPS Connection programmatically in Java

I create a class HttpUtil

Usage example

HttpUtil http = new HttpUtil();
 

http.setDoOutput(true); 
http.setDoInput(true);
http.setContentType("application/x-www-form-urlencoded");
http.setAllowUserInteractions(false);
           
String response = http.request("www.mydomain.com/process.php", params, "POST");


System.out.println(response);

params should be a HashMap for example

HashMap<String, String> params = new HashMap<String, String> ();
params.put("username","ali");
params.put("password","somepassword");

No comments: