3
connection = (HttpURLConnection)new URL(mURL).openConnection();
connection.setRequestMethod("GET");
String basicAuth = params[0] + ":" + params[1];
basicAuth = "Basic " + new String(Base64.encode(basicAuth.getBytes(),Base64.NO_WRAP));
connection.setRequestProperty("Authorization",basicAuth);
connection.connect();
InputStream in = connection.getInputStream();

これに基づいて考えられるすべての質問をSOで調べましたが、成功しませんでした。基本認証を使用してサーバーに接続しようとしています。しかし、そこから入力ストリームにアクセスしようとすると、URLConnectionがスローされIOExceptionます。あなたのいずれかからの助けに感謝します。

4

1 に答える 1

1

Basically, here there could be a few things that can go wrong. Does the URL you are trying to connect to exist? If not, may be you may have to redirect. Also, try

connection.getResponseCode();

and make sure it returns 200 or HTTP_OK

Needs more information to say anything. Go to debug mode and try to get the states of different objects used here.

Similar to IOException: "Received authentication challenge is null" (Apache Harmony/Android)

于 2013-10-29T02:03:21.120 に答える