从android中的HttpURLConnection获取响应代码

发布于 2024-12-26 16:36:20 字数 182 浏览 3 评论 0原文

我正在与服务器建立连接并且工作正常。但有时当我尝试获取响应代码时(当服务器返回 401、403、404 时),我会收到 IO 异常。我正在根据响应代码处理一切。因此,当它抛出 IO 异常时,

http.getResponseCode()

我无法读取响应代码。请为此提出一个解决方案。

i am establishing connection with the server and its working fine. But there are times when i try to get the response code (when server is throwing back 401, 403, 404) i am getting IO Exception. I am handling everything based on the response code. So when it throws IO exception on

http.getResponseCode()

i am not able to read the response code. Please suggest a solution for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2025-01-02 16:36:20

在 android 2.3 之前,HttpUrlConnection 几乎没有问题。最好使用 Defaulthttpclient api。您的问题似乎与类似。

Prior to android 2.3 HttpUrlConnection has few issues. Its better to use Defaulthttpclient api. Seems your issue is similar to this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文