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 closed by peer
如果我在apn中使用url.OpenConnection()wuithout Proxy而没有Proxysettings,代码可以工作,可能是什么问题?
@R_502_6120@ 您可以尝试这种注册代理服务器的替代方法:PropertIEs systemSettings=System.getPropertIEs();systemSettings.put("http.proxyHost","your.proxy.host.here");systemSettings.put("http.proxyPort","8080"); // use actual proxy port总结
以上是内存溢出为你收集整理的android – 使用代理的HttpsUrlConnection全部内容,希望文章能够帮你解决android – 使用代理的HttpsUrlConnection所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)