Android HTTPS Post Issue



我通过 post 方法向 https 连接提交表单时遇到了一些问题。

通常的错误是:

java.net.UnknownHostException

但是我有时会遇到错误,例如对等方关闭连接

将表单提交到 http url 似乎可以无缝工作,但是当使用 https 连接时,它似乎会带来很多问题。

服务器证书有效(由Go Daddy签名),我看不到任何问题,因为我可以让iOS设备正常提交。

我已经尝试了这些解决方案,但它们似乎没有太大区别:

安卓中的安全 HTTP 帖子

如何在安卓中发布HTTPS帖子

安卓HTTPS帖子 - 不工作

安卓 SSL https 帖子

使用 ksoap2-android 的不受信任证书

有没有人有有用的教程或可能解释如何执行https帖子?

谢谢:)

URL url = new URL("https://www.xyz.com");
HttpsURLConnection httpURLConnection  = (HttpsURLConnection) url.openConnection();
httpURLConnection.setRequestProperty("Content-Type",
                "text/plain");
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setAllowUserInteraction(false);
httpURLConnection.setInstanceFollowRedirects(true);
httpURLConnection.setHostnameVerifier(DO_NOT_VERIFY);
httpURLConnection.connect();
OutputStream outputStream = httpURLConnection.getOutputStream();
 outStream.write(datainbytes);

 final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
 };

这对我来说完美无缺。

最新更新