http認証に問題があります。 認証なしで他のWebサービスと接続する場合は問題ありません。 しかし、私はどのように私はアンドロイドでこのHTTP認証に接続できるかわかりません。 私のアプリでは、私は2つのテキストフィールド(ログインとパスワード)があります。また、アドレスに接続してユーザーに関する情報(jsonデータ)を取得するためのボタン。 初めて、住所:https://proxyepn-test.epnbn.net/wsapi/userに識別子を渡したいと思います。 https://login:[email protected]/wsapi/userのように。そして、データをログに表示します。 私を助けることができますか?androidでhttp認証
「 私はこれを試します。 //クラス
public HashMap<String, String> btn_connexion(View view) {
etPseudo = (EditText) findViewById(R.id.editText);
etMdp = (EditText) findViewById(R.id.editText2);
final String pseudo = etPseudo.getText().toString();
final String mdp = etMdp.getText().toString();
//String urldisplay = "https://" + pseudo + ":" + mdp + "@proxyepn-test.epnbn.net/wsapi/user";
@Override
public Map<String, String> getHeaders() throws AuthFailureErro {
HashMap<String, String> params = new HashMap<>();
String creds = String.format("%s:%s", pseudo, mdp);
String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP);
params.put("Authorization", auth);
return params;
}
}`
認証なし
String restURL = "https://proxyepn-test.epnbn.net/wsapi/epn";
RestOperation test = new RestOperation();
String[]tabInfos = null;
try {
String test2 = test.execute(restURL).get().toString();
Log.i("result",test2);
JSONObject obj = new JSONObject(test2);
JSONObject data = obj.getJSONObject("data");
Iterator<String> iterator = data.keys();
while(iterator.hasNext()){
String key = iterator.next();
String name = data.getString(key);
tabInfos = name.split(",");
...
}
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
THXしかし、私はそうではありませんこれを使用する方法を知っている。私は私の質問をより正確に編集します。 –
@GregConstantin私はあなたのRestOperationクラスdoInBackgroundメソッドでこれらの行を追加する答えを編集しました – d1vivek681065
私はsetRequestPropertyでエラーがあります。 –