karthikeyan sivanantham

Greenhorn
+ Follow
since Dec 03, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by karthikeyan sivanantham

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());


}
}