HttpsURLConnection和间歇性连接

编程入门 行业动态 更新时间:2024-10-24 10:16:30
本文介绍了HttpsURLConnection和间歇性连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望有人可以帮助我间歇性连接我 获得使用code与HttpsURLConnection。在code我使用的是 如下:

I'm hoping someone could help me out with intermittent connections I'm getting using code with HttpsURLConnection. The code I'm using is below:

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setReadTimeout(10 * 1000); if conn.getResponseCode() != 200) { Log.v(TAG, "error code:" + conn.getResponseCode()); }

该连接工作在第一时间每次,当我用它来拉 JSON文件。然而,当我使用的连接再次发送指令, 它总是失败的第一次。然后,它通常工作,如果我送 如果我等一会儿命令迅速(5秒内),但失败。 我不认为它是一个SSL问题,因为它第一次连接 正确的,但我在这里可能是错的。我也尝试过许多不同 的变化,如添加:

The connection works the first time everytime when I use it to pull a json file. However, when I use the connection again to send a command, it always fails the first time. It then typically works if I send the command quickly ( within 5 seconds), but fails if I wait a while. I don't think its a SSL issue because it connects the first time correctly, but I could be wrong here. I also tried many different variations such as adding:

conn.setUseCaches(false); conn.setRequestProperty("Connection","Keep-Alive"); conn.getHostnameVerifier(); conn.getSSLSocketFactory(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); conn.wait(100);

不过,我没有运气。任何帮助将大大AP preciated。

However, I had no luck. Any help would be greatly appreciated.

推荐答案

尝试 System.setProperty(http.keepAlive,假); 在此之前

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

更多推荐

HttpsURLConnection和间歇性连接

本文发布于:2023-11-16 15:56:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间歇性   HttpsURLConnection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!