You don't have a target host.
Try something like this. Note the execute on DefaultHttpClient..
Did a quick cut and paste so you will have to fix it up..

        DefaultHttpClient cli = new DefaultHttpClient();
       HttpGet method = null;
        HttpHost targetHost = null;
        HttpHost proxy = null;

         cli.getCredentialsProvider().setCredentials(
                    new AuthScope(ServerComm.ProxyAddress,
ServerComm.ProxyPort),
                    new
UsernamePasswordCredentials(ServerComm.ProxyUser, ServerComm.ProxyPw)
                    );

            targetHost = new HttpHost(ServerComm.ServerSite,
ServerComm.ServerPort, ServerComm.Method);
            proxy = new HttpHost(ServerComm.ProxyAddress, ServerComm.ProxyPort);

            cli.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

            try {
                URI newUri =  new URI(url);
                method = new HttpGet(newUri.getRawPath() + "?" +
newUri.getRawQuery());


            } catch (URISyntaxException ex) {
                System.out.println("URI Encode Error " + ex.toString());
                isCorrect = false;
                return 1;
            }

        HttpResponse resp = null;
        HttpEntity ent = null;



        //execute the method

        String responseBody = null;

        try{

                resp = cli.execute(targetHost,method);


           ent = resp.getEntity();
        }

On Mon, Jan 24, 2011 at 6:50 PM, Rodrigo B. Campacci
<[email protected]> wrote:
> Hi,
>
> I'm trying to make a GET request through a HTTP proxy (squid) with basic
> authentication (user and password).
>
> I found a sample of how to do that using version 3.0, but for version 4.x I
> can't found this.
>
> I'm using the code below, but it isn't working.
>
>        HttpRequestBase httpmethod = null;
>        HttpResponse response = null;
>        DefaultHttpClient httpclient = null;
>        HttpHost proxy = null;
>
>      StringBuilder resultText = new StringBuilder("");
>
>      httpclient = new DefaultHttpClient();
>
>      proxy = new HttpHost(proxyHost, proxyPort);
>      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
> proxy);
>
>        httpclient.getCredentialsProvider().setCredentials(
>                                                new AuthScope(proxyHost,
> proxyPort),
>                                                new
> UsernamePasswordCredentials(proxyUserName, proxyPassword));
>
>        httpmethod = new HttpGet(url);
>      response = httpclient.execute(httpmethod);
>
> Below an extract from the log:
> 2011/01/24 00:13:47:054 GMT [DEBUG] DefaultHttpClient - Proxy requested
> authentication
> 2011/01/24 00:13:47:054 GMT [DEBUG] DefaultProxyAuthenticationHandler -
> Authentication schemes in the order of preference: [negotiate, NTLM, Digest,
> Basic]
> 2011/01/24 00:13:47:054 GMT [DEBUG] DefaultProxyAuthenticationHandler -
> Challenge for negotiate authentication scheme not available
> 2011/01/24 00:13:47:055 GMT [DEBUG] DefaultProxyAuthenticationHandler -
> Challenge for NTLM authentication scheme not available
> 2011/01/24 00:13:47:055 GMT [DEBUG] DefaultProxyAuthenticationHandler -
> Challenge for Digest authentication scheme not available
> 2011/01/24 00:13:47:055 GMT [DEBUG] DefaultProxyAuthenticationHandler -
> Basic authentication scheme selected
> 2011/01/24 00:13:47:064 GMT [DEBUG] DefaultHttpClient - Authorization
> challenge processed
> 2011/01/24 00:13:47:065 GMT [DEBUG] DefaultHttpClient - Authentication
> scope: BASIC '*Enter user and password*'@192.168.160.3:8080
> 2011/01/24 00:13:47:065 GMT [DEBUG] DefaultHttpClient - Found credentials
> 2011/01/24 00:13:47:066 GMT [DEBUG] DefaultClientConnection - Connection
> closed
> 2011/01/24 00:13:47:066 GMT [DEBUG] DefaultClientConnectionOperator -
> Connecting to /192.168.160.3:8080
> 2011/01/24 00:13:47:741 GMT [DEBUG] RequestAddCookies - CookieSpec selected:
> best-match
> 2011/01/24 00:13:47:747 GMT [DEBUG] DefaultClientConnection - Connection
> shut down
>
> Anyone could help?
>
> Thanks,
>
> Rodrigo B. Campacci
> [email protected]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to