大佬教程收集整理的这篇文章主要介绍了android – 使用代理的HttpsUrlConnection,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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(); }
现在我收到错误:
如果我在apn中使用url.openConnection()wuithout Proxy而没有ProxysetTings,代码可以工作,可能是什么问题?
以上是大佬教程为你收集整理的android – 使用代理的HttpsUrlConnection全部内容,希望文章能够帮你解决android – 使用代理的HttpsUrlConnection所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。