viernes, 30 de marzo de 2012

Android: Make httprequest behind a firewall

How you set up a proxy addres in your Android application:

If you have something like this in your current Android application:


HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(this.url);

Well, add a new call to the following method:



 public void setProxy(DefaultHttpClient httpclient) {  
           final String PROXY_IP = "<insert your IP here>";  
            final int PROXY_PORT = <insert_PROXY_PORT#>;  

            httpclient.getCredentialsProvider().setCredentials(  
                    new AuthScope(PROXY_IP, PROXY_PORT),  
                    new UsernamePasswordCredentials(  
                            "username", "password"));  

           HttpHost proxy = new HttpHost(PROXY_IP, PROXY_PORT);  

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


       }  


Like this:

setProxy( (DefaultHttpClient)httpClient );

And that will let you use a proxy!



Android: Unable to make httprequest behind firewall - Stack Overflow