English 中文(简体)
HttpsUrlConnection with Proxy
原标题:HttpsUrlConnection with Proxy

我有一部法典,可以与HttpsUrlConnection一起执行《社会、文化权利国际公约》中的要求,但该法典的某些使用者拥有一个封闭的用户组的SIM卡,他们需要在自己身上设置代理。 如果他们确定代理人,就需要修改我的代码。 我对此表示担忧:

    HttpsURLConnection connection = null;
    DataOutputStream outputStream = null;
    DataInputStream inputStream = null;
    String urlServer = "https://xxx";
    String boundary = "*****";

try {

    URL url = new URL(urlServer);
    SocketAddress sa = new InetSocketAddress("[MY PROXY HOST]",[My PROXY PORT]);
    Proxy mProxy = new Proxy(Proxy.Type.HTTP, sa);

    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setUseCaches(false);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Connection", "Keep-Alive");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;boundary=" + boundary);

    //this is supposed to open the connection via proxy
    //if i use url.openConnection() instead, the code works
    connection = (HttpsURLConnection) url.openConnection(mProxy);

    //the following line will fail
    outputStream = new DataOutputStream(connection.getOutputStream());

    // [...] 

} catch (Exception ex) {
   ret = ex.getMessage();
}

我现在收到错误:

javax.net.ssl.SSLException:链接由同行关闭

如果使用尿液。 开放Connection () wuithout Proxy and without Proxyppings in the apn, the Code work, what may be the Problem?

最佳回答

您可以尝试这种登记代理服务器的替代方式:

Properties systemSettings=System.getProperties();

systemSettings.put("http.proxyHost", "your.proxy.host.here");
systemSettings.put("http.proxyPort", "8080"); // use actual proxy port
问题回答

您可使用NetCipher的图书馆,在使用时,便利代位和现代TLS config。 电话:NetCipher.setProxy() ,以建立全球对应代理。 NetCipher also configures the HttpsURLConnection instance to use the better support TLS edition,movs SSLv3 support, and configures the Bestripe of ciphers for that TLS edition. 首先,在build.gradle上添加:

compile  info.guardianproject.netcipher:netcipher:1.2 

或您可下载netcipher-1.2.jar,并直接列入您的附录。 然后,不要说:

HttpURLConnection connection = (HttpURLConnection) sourceUrl.openConnection(mProxy);

呼吁:

NetCipher.setProxy(mProxy);
HttpURLConnection connection = NetCipher.getHttpURLConnection(sourceUrl);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签