1

I am making a broswer type app i want to set the proxy only for this browser

I tried to modify global proxy by using this code but it does not work

System.getProperties().put("http.proxyHost", "someProxyURL");
System.getProperties().put("http.proxyPort", "someProxyPort");
System.getProperties().put("http.proxyUser", "someUserName");
System.getProperties().put("http.proxyPassword", "somePassword");
System.getProperties().put("http.proxySet", "true");

So I looked at proxySelector class and I really don't understand how to set the proxy for my brower

I know there is a hidden class in ProxySelector in com.android.settings/.ProxySelector

But I have to manually entered the proxy.

Is there any way so that i can configure proxy only for mybrowser(Just a Webview) ??

Please Help. Thanks in Advance!!!

Sunny
  • 14,522
  • 15
  • 84
  • 129
  • Possible duplicate question: http://stackoverflow.com/questions/4488338/webview-android-proxy – Robert Apr 11 '12 at 15:12
  • @Robert Thanks for your response I have found a solution which open a hidden activity com.android.settings.ProxySelector. Now I can set The proxy. But this activity does not have username/password field Can you guide me how can i set usename/password field so that i can open a webpage in webview. Now webview say forbidden because username/password is not set? – Sunny Apr 11 '12 at 17:25
  • @Robert I looked at your link also but it always giving null on network Object. – Sunny Apr 11 '12 at 17:47
  • Worth noting here that http.proxySet is an urban myth. Setting it has no effect. – user207421 Apr 11 '12 at 18:19

2 Answers2

1
System.getProperties().put("http.proxyUser", "someUserName");
System.getProperties().put("http.proxyPassword", "somePassword");

These dont' work in the JDK, only in the Apache HTTP client.

System.getProperties().put("http.proxySet", "true");

This is an urban myth. It appears in some early Java books but has never done anything in the JDK. It is a relic of the defunct HotJavaBean browser c. 1998.

user207421
  • 305,947
  • 44
  • 307
  • 483
-1

You should use it like

Authenticator.setDefault(
   new Authenticator() {
      public PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication(
              authUser, authPassword.toCharArray());
     }
   }
);

System.setProperty("http.proxyHost", someProxyURl);
System.setProperty("http.proxyPort", someProxyPort);
System.setProperty("http.proxyUser", someProxyUser);
System.setProperty("http.proxyPassword", someProxyPassword);
....
Sumit Lubal
  • 329
  • 2
  • 13
  • `proxyUser` and `proxyPassword` are for the Apache HTTP client. They do nothing in the JDK. Setting the `Authenticator` is sufficient. – user207421 Mar 16 '17 at 18:18