離れたサーバーから xml ファイルを取得しようとしています。サーバーはユーザー名とパスワードを要求します。
私のコードは Android 4.x では問題なく動作しますが、Android 2.xi ではエラー 400 が発生します。
400不正な要求
お使いのブラウザは、このサーバーが理解できないリクエストを送信しました。
ここに私のコードがあります:
URL url = new URL("http://username:password@xx.xx.xx.xx:80/pathToXML/file.xml");
URLConnection uc = url.openConnection();
String val = (new StringBuffer("username").append(":").append("password")).toString();
byte[] base = val.getBytes();
String authorizationString = "Basic " + new String(Base64.encode(base, Base64.DEFAULT));
uc.setRequestProperty("Authorization", authorizationString);
uc.connect();
InputStream ins = uc.getInputStream(); // it fails on this line
私は多くのことを試しました (Content-Length、SetRequestMethod を POST に追加し、user-Agent を設定しました) が、うまくいきません。
誰かが何かアイデアを持っているなら、私はそれを受け入れます。
どうもありがとうございました。
乾杯