Android的代理服务器设置 [英] Android Proxy Setting

查看:735
本文介绍了Android的代理服务器设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要浏览一些网站,代理,我已经(与我要让当然,应用程序)。我想以编程方式改变它(没有去设置或其他3提供的应用程序)。

I want to browse some website with proxy that i already have (with apps that i want to make of course). i want to change it programmatically (without go to settings or other 3rd apps included).

下面是我做了什么:

public class WebViewActivity extends Activity {


 WebView web;
 String PROXY_IP = "MyProxy";  
 int PROXY_PORT = MyPort; 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_view);

        web = (WebView) findViewById(R.id.webView1);
        web.setWebViewClient(new myWebClient());
        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl("MyURL");

        if (PROXY_IP != null) {                 
        DefaultHttpClient httpClient = new DefaultHttpClient();
         httpClient.getCredentialsProvider().getCredentials(new AuthScope(PROXY_IP, PROXY_PORT));  
         new UsernamePasswordCredentials("username","passsword");
        HttpHost proxy = new HttpHost(PROXY_IP, PROXY_PORT);             

        }
    }

我用的WebView这一点。我已经尝试过使用PhoneGap的,只是编辑的资产。但我感到困惑的一些PHP code。所以我决定使用的WebView替代。

I use webview for this. i already tried using phonegap and just editing the asset. but i'm confused about some php code. so i decided using webview instead.

现在的问题是如何使用我的代理,使我的WebView。

The Problem is how to make my webview using my proxy.

注:我使用GB 2.3

Note: i'm using GB 2.3

推荐答案

问题解决了。在web视图的onCreate 我必须调用网址。像这样网​​络= callURL(); 并加载URL中使用loadDatawithBaseUrl。之后,你必须做出一个公共类callURL(){。设置代理在那里。像这样

Problem Solved. in webview onCreate i have to call url. like this web = callURL(); and to load url use loadDatawithBaseUrl. after that you have to make a public class callURL(){ . set the proxy in there. like this

DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpHost proxy = new HttpHost("your host", your proxy); //proxy that i need
    httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
    httpClient.getCredentialsProvider().setCredentials(  
            new AuthScope("your host", your proxy),  
            new UsernamePasswordCredentials(  
                    "your username", "your password"));

,然后在HTTPGET。打电话给你的网址了。而已。好运气

and then in httpget. call your url too. thats it. good luck

这篇关于Android的代理服务器设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆