得到响应code从HttpURLConnection的android系统系统、code、HttpURLConnection、android

2023-09-05 07:40:26 作者:つ独自买醉

我与服务器建立连接,其工作的罚款。但有时当我尝试获得响应code(当服务器被抛回401,403,404),我得到IO异常。我是基于响应code处理一切。因此,当它抛出IO异常对

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()

我不能够读取响应code。请提出一个解决方案。

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

推荐答案

在此之前的Andr​​oid 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.