hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh Gordineer <joshg...@yahoo.com>
Subject Fw: SOCKS proxy example??
Date Tue, 20 Apr 2010 17:53:24 GMT
I've been trying to implement a SOCKS proxy using Apache HttpClient 4.0.1 and haven't found
a straightforward example, most proxy examples focus on http proxies.


I want to access a protected resource that is accessible behind a socks proxy.  I can curl
the resource like so:

curl --socks4 socks.somewhere.com:1080 http://www.somewhere.com/hidden

However with the following code:

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpHost proxy = new HttpHost("socks.somewhere.com", 1080);
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    HttpGet httpget = new HttpGet("http://www.somewhere.com/hidden");
    HttpResponse response = httpclient.execute(httpget);
    System.out.println(response.getStatusLine());
    HttpEntity entity = response.getEntity();
    if (entity != null) {
      entity.consumeContent();
    }
    httpclient.getConnectionManager().shutdown();

I get an exception:

Exception in thread "main" org.apache.http.NoHttpResponseException: The target server failed
to respond
    at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:101)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:210)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:271)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:227)
    at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:209)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:292)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:126)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:483)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)

I have been able to do something with the JDK Proxy and HttpUrlConnection but haven't gotten
anything working in HttpClient.

Any input would be appreciated.  I've done a few web searches, but haven't come up with anything
definitive.

Thanks in advance..
Josh
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message