Closed GoogleCodeExporter closed 8 years ago
Again from a mail by Bala:
I have tested the code snippet that I have sent to you for proxy configuration.
HttpClient is not taking the proxy details from system variables. Try the
following
snippet.. It is working.
package com.bala.samples.httpclient ;
import java.io.InputStream;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod ;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;
/**
*
* @author bala
*
*/
public class Sample {
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
HostConfiguration hc = new HostConfiguration();
hc.setProxy( "proxy", 8080);
client.setHostConfiguration(hc);
// If Proxy authentication required
//Credentials credentials = new UsernamePasswordCredentials( "bala" ,
"password");
//client.getState().setProxyCredentials( null , credentials);
HttpMethod method = new GetMethod("http://www.google.com");
System.out.println(client.executeMethod(method));
InputStream stream = method.getResponseBodyAsStream();
int ch = -1;
while( (ch = stream.read()) != -1){
System.out.print((char) ch);
Original comment by subwiz
on 12 Dec 2007 at 2:41
svn ci #56 has the proxy implementation. Yet to know the result of testing from
Bala.
Original comment by subwiz
on 14 Dec 2007 at 1:04
Fixed and tested by Bala.
Original comment by subwiz
on 19 Dec 2007 at 3:05
Original issue reported on code.google.com by
subwiz
on 5 Dec 2007 at 3:49