When you want to post some values to a specific URL using java you can use http components fromĀ http://hc.apache.org/httpclient-3.x/


You can use part of the following code

DefaultHttpClient httpclient = new DefaultHttpClient();
// The following is if you want to pass http authentication credentials
                new AuthScope("posturl", 80),
                new UsernamePasswordCredentials("username", "password"));
// Now pass some parameters to the url
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("param1", value1));
params.add(new BasicNameValuePair("param2", value2));
String charset="your charset";
   UrlEncodedFormEntity query = new UrlEncodedFormEntity(params, charset);
   HttpPost post = new HttpPost(posturl);
   post.getParams().setParameter("http.protocol.content-charset", charset);
   post.getParams().setParameter("http.useragent", "Test Client");
   ResponseHandler<String> responseHandler = new BasicResponseHandler();
   String responseBody = httpclient.execute(post, responseHandler);
catch (Exception e) {
} finally {
  // close the connection


By admin