我有一部法典,可以与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?