use of okhttp3.HttpUrl.Builder in project samourai-wallet-android by Samourai-Wallet.
the class WebUtil method tor_getURL.
private String tor_getURL(String URL, Map<String, String> headers) throws Exception {
OkHttpClient.Builder builder = new OkHttpClient.Builder().proxy(TorManager.getInstance(this.context).getProxy()).connectTimeout(90, TimeUnit.SECONDS).readTimeout(90, TimeUnit.SECONDS);
if (BuildConfig.DEBUG) {
builder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
}
if (URL.contains("onion")) {
getHostNameVerifier(builder);
}
Request.Builder rb = new Request.Builder().url(URL);
// set headers
if (headers == null) {
headers = new HashMap<>();
}
for (Map.Entry<String, String> e : headers.entrySet()) {
rb = rb.header(e.getKey(), e.getValue());
}
Request request = rb.build();
try (Response response = builder.build().newCall(request).execute()) {
if (response.body() == null) {
return "";
}
return response.body().string();
}
}
use of okhttp3.HttpUrl.Builder in project EnableHands by LeviWGG.
the class ServiceFactory method getOkhttpClient.
public OkHttpClient getOkhttpClient() {
OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
File cachefile = new File(MyApplication.getMyContext().getExternalCacheDir(), "");
Cache cache = new Cache(cachefile, 1024 * 1024 * 30);
builder.cache(cache);
HttpLogInterceptor httpLogInterceptor = new HttpLogInterceptor();
builder.addInterceptor(httpLogInterceptor);
CacheInterceptor cacheInterceptor = new CacheInterceptor();
builder.addInterceptor(cacheInterceptor);
builder.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
builder.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
return builder.build();
}
use of okhttp3.HttpUrl.Builder in project AndroidComponent by funnyzhaov.
the class HeaderInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request originalrequest = chain.request();
Request.Builder builder = originalrequest.newBuilder().header("xx", "xx").method(originalrequest.method(), originalrequest.body());
Request request = builder.build();
return chain.proceed(request);
}
use of okhttp3.HttpUrl.Builder in project PocketMaps by junjunguo.
the class HttpConnection method getOkHttpClient.
private static OkHttpClient getOkHttpClient() {
if (client == null) {
Builder b = new Builder();
b.connectTimeout(TIMEOUT_CONNECTION, TimeUnit.MILLISECONDS);
b.readTimeout(TIMEOUT_SOCKET, TimeUnit.MILLISECONDS);
client = b.build();
/*
client.setConnectTimeout(TIMEOUT_CONNECTION, TimeUnit.MILLISECONDS);
client.setReadTimeout(TIMEOUT_SOCKET, TimeUnit.MILLISECONDS);
*/
}
return client;
}
use of okhttp3.HttpUrl.Builder in project android-diplicity by zond.
the class RetrofitActivity method recreateServices.
protected void recreateServices() {
AuthenticatingCallAdapterFactory adapterFactory = new AuthenticatingCallAdapterFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request toIssue = chain.request().newBuilder().addHeader("Accept", "application/json; charset=UTF-8").addHeader("X-Diplicity-API-Level", "" + DIPLICITY_API_LEVEL).build();
if (getLocalDevelopmentMode() && !getLocalDevelopmentModeFakeID().equals("")) {
HttpUrl url = toIssue.url().newBuilder().addQueryParameter("fake-id", getLocalDevelopmentModeFakeID()).build();
toIssue = toIssue.newBuilder().url(url).build();
} else if (!getAuthToken().equals("")) {
toIssue = toIssue.newBuilder().addHeader("Authorization", "bearer " + getAuthToken()).build();
}
Log.d("Diplicity", "" + toIssue.method() + "ing " + toIssue.url());
return chain.proceed(toIssue);
}
});
builder.connectTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS);
Gson gson = new GsonBuilder().registerTypeAdapter(Ticker.class, new TickerUnserializer()).registerTypeAdapter(Game.class, new GameUnserializer(this)).create();
Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseURL()).addConverterFactory(GsonConverterFactory.create(gson)).addCallAdapterFactory(adapterFactory).client(builder.build()).build();
gameService = retrofit.create(GameService.class);
userStatsService = retrofit.create(UserStatsService.class);
memberService = retrofit.create(MemberService.class);
rootService = retrofit.create(RootService.class);
variantService = retrofit.create(VariantService.class);
optionsService = retrofit.create(OptionsService.class);
orderService = retrofit.create(OrderService.class);
phaseService = retrofit.create(PhaseService.class);
channelService = retrofit.create(ChannelService.class);
messageService = retrofit.create(MessageService.class);
phaseResultService = retrofit.create(PhaseResultService.class);
gameResultService = retrofit.create(GameResultService.class);
phaseStateService = retrofit.create(PhaseStateService.class);
gameStateService = retrofit.create(GameStateService.class);
userConfigService = retrofit.create(UserConfigService.class);
banService = retrofit.create(BanService.class);
}
Aggregations