嗨,在我的 android 应用程序中,我将 HttpUrlconnection 用于 Web 服务。因此,对于任何带有响应 401 的 Web 资源请求,它都不会提供任何标头字段或响应代码。它显示内容长度 -1。它会引发异常java.io.IOException: Received authentication challenge is null
。现在我的问题是如何检查这种情况的响应代码。需要帮忙。我在休息客户端检查了这些请求,在那里我发现我的响应正确地带有带有 401 和其他字段的标头响应代码
我的请求看起来像
String urlString ="http://WWW.ABC.com";
URL url = new URL(urlString);
login_urlConnection = (HttpURLConnection) url.openConnection();
login_urlConnection.setRequestMethod("GET");
int statusCode = login_urlConnection.getResponseCode() // Here I am getting exception I want this status code to check authentication failure
如何解决这个问题呢。需要帮忙。谢谢你。
我使用 HttpClient 进行了相同的调用,然后我能够获得响应代码,那么为什么不使用 HttpUrlConnection。我做错了什么需要帮助。