• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

connection timed out with commons httpclient

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm trying to post to a website using the apache common httpclient util and I'm using borrowed code from the net to power my app, when I run my app, I get a connection time out error. my app is sitting behing a corporate proxy and I guess my app is not able to reach the website through the proxy, can someone let me know how to get through?

I'm posting my code and the error below

Karthik

THE ERROR:


Dec 3, 2008 6:23:26 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
Dec 3, 2008 6:23:26 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
Exception in thread "main" java.net.NoRouteToHostException: No route to host: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)

THE CODE:

package site_login_eg;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;




public class Main
{

public static void main(String[] args) throws Exception {

HttpClient client = new HttpClient();

GetMethod getPage = new GetMethod("http://www.hackthissite.org");

client.executeMethod(getPage);

PostMethod postLogin = new PostMethod("http://www.hackthissite.org/pages/index/index2.php");

NameValuePair[] data = {
new NameValuePair("txt_username", "MYUSERNAME"),
new NameValuePair("txt_password", "MYPASSWORD"),
new NameValuePair("btn_submit","Login")

};

postLogin.setRequestBody(data);

client.executeMethod(postLogin);


//this is a request to a page that requires authentication
GetMethod getPage2 = new GetMethod("http://www.hackthissite.org/missions/basic/");

client.executeMethod(getPage2);

System.out.println(getPage2.getResponseBodyAsString());


}
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic