エミュレータのプロキシ認証
やったこと。
エミュレータの設定でプロキシ設定する
うまくいかなかったのでコマンドライン上でabd, emulatorを使うことにした。
まずパスを通した。
export PATH=/Applications/adt-bundle-mac-x86_64***/sdk/platform-tools:$PATH export PATH=/Applications/adt-bundle-mac-x86_64***/sdk/tools:$PATH
使い方は
emulator -list-avds
で機種一覧がみれる。
プロキシ経由での実行は
emulator -avd devicename -http-proxy http://username:password@proxyhost:port
abdの使い方は以下に詳しい。
qiita.com
googleのブラウザで認証を求められて入れたら検索できるようになった。
しかし、自分のアプリではproxyでエラーになっている。
アプリをいじる
HTTPクライアントにプロキシ認証を仮にできるようにした。
OkHttpClientを使っているのでリクエストを投げる際に以下のように追加した。
Authenticator authenticator = new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException { String credentioal = Credentials.basic(username, password); return response.request().newBuilder().header("Proxy-Authorization", credentioal).build(); } }; Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyhost,port) ); OkHttpClient client = new OkHttpClient().newBuilder() .proxy(proxy) .authenticator(authenticator) .proxyAuthenticator(authenticator) .build();
これでプロキシをさしあたり通すことができた。
OKHTTPの使い方は
qiita.com