Androidアプリ Basic認証 DefaultHttpClient java

Android DefaultHttpClient

DefalutHttpClientで認証アクセス
以下のコードでは、Basic認証が行えるようになる。


この辺をインポートして使用。
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

DefaultHttpClient httpClient = new DefaultHttpClient();
Credentials credentials = new UsernamePasswordCredentials("HOGE","foofoo");
AuthScope scope = new AuthScope("www.hoge.ne.jp", 80);
httpClient.getCredentialsProvider().setCredentials(scope, credentials);

StringBuilder uri = new StringBuilder("http://www.hoge.ne.jp/hogehoge.txt");
HttpGet request = new HttpGet(uri.toString());
HttpResponse httpResponse = null;
try {
    httpResponse = httpClient.execute(request);
} catch (Exception e) {
    Log.d(TAG, "Error Execute");
}

-Androidアプリ, Basic認証, DefaultHttpClient, java
-, , ,

Copyright© LAPTURE , 2020 All Rights Reserved.