从android中的HttpURLConnection获取响应代码
我正在与服务器建立连接并且工作正常。但有时当我尝试获取响应代码时(当服务器返回 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 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.