h-tadagawa / rest-client

Automatically exported from code.google.com/p/rest-client
Apache License 2.0
0 stars 0 forks source link

Proxy Support #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
From a mail from Balasubramani S.D:

Hello Subhash,
Add proxy configuration also then it will be helpful for the users those
are working behind proxy. Just three lines of code,

System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "myProxyMachineName" );
System.getProperties().put( "proxyPort", "85" );

Regards,
Bala.

Original issue reported on code.google.com by subwiz on 5 Dec 2007 at 3:49

GoogleCodeExporter commented 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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
Fixed and tested by Bala.

Original comment by subwiz on 19 Dec 2007 at 3:05