use of okhttp3 in project Retrofit-Android-Basic by basil2style.
the class ServiceGenerator method createService.
public static <S> S createService(Class<S> serviceClass, final String authToken) {
if (authToken != null) {
httpClient.interceptors().add(new Interceptor() {
@Override
public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder().header("Authorization", authToken).method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
}
OkHttpClient client = httpClient.build();
Retrofit retrofit = builder.client(client).build();
return retrofit.create(serviceClass);
}
use of okhttp3 in project xmall by Exrick.
the class QiniuUtil method qiniuBase64Upload.
public static String qiniuBase64Upload(String data64) {
String key = renamePic(".png");
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
// 服务端http://up-z2.qiniup.com
String url = "http://up-z2.qiniup.com/putb64/-1/key/" + UrlSafeBase64.encodeToString(key);
RequestBody rb = RequestBody.create(null, data64);
Request request = new Request.Builder().url(url).addHeader("Content-Type", "application/octet-stream").addHeader("Authorization", "UpToken " + getUpToken()).post(rb).build();
System.out.println(request.headers());
OkHttpClient client = new OkHttpClient();
okhttp3.Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(response);
return origin + key;
}
use of okhttp3 in project curb by irijwj.
the class RetrofitGetData method postAnswer.
public static String postAnswer(String strEntity) {
RequestBody description = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), strEntity);
Call<String> postAnswerCall = serverInterface.postAnswer(description);
Response<String> response;
String postResult = null;
try {
response = postAnswerCall.execute();
if (response.isSuccessful()) {
postResult = response.body();
}
} catch (IOException e) {
e.printStackTrace();
}
return postResult;
}
use of okhttp3 in project run-wallet-android by runplay.
the class RunIotaAPICore method postConstruct.
/**
* added header for IRI
*/
private void postConstruct() {
boolean USE_AUTH = false;
// if(host.contains(".runplay.com") || host.contains(".runpg.com"))
// USE_AUTH=true;
final String nodeUrl = protocol + "://" + host + ":" + port;
if (USE_AUTH) {
// Log.e("IRI-CONNECT","Using Auth OK");
String creds = Base64.encodeToString((uname + ":" + upassword).getBytes(), false);
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = builder.readTimeout(5000, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder().addHeader(X_IOTA_API_VERSION_HEADER_NAME, X_IOTA_API_VERSION_HEADER_VALUE).addHeader("Authorization", "Basic " + creds).build();
return chain.proceed(newRequest);
}
}).connectTimeout(5000, TimeUnit.SECONDS).build();
// use client to create Retrofit service
final Retrofit retrofit = new Retrofit.Builder().baseUrl(nodeUrl).addConverterFactory(GsonConverterFactory.create()).client(client).build();
service = retrofit.create(IotaAPIService.class);
} else {
// Log.e("IRI-CONNECT","NOOTTTTT Using Auth");
final OkHttpClient client = new OkHttpClient.Builder().readTimeout(5000, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder().addHeader(X_IOTA_API_VERSION_HEADER_NAME, X_IOTA_API_VERSION_HEADER_VALUE).build();
return chain.proceed(newRequest);
}
}).connectTimeout(5000, TimeUnit.SECONDS).build();
// use client to create Retrofit service
final Retrofit retrofit = new Retrofit.Builder().baseUrl(nodeUrl).addConverterFactory(GsonConverterFactory.create()).client(client).build();
service = retrofit.create(IotaAPIService.class);
}
// Create OkHttpBuilder
log.debug("Jota-API Java proxy pointing to node url: '{}'", nodeUrl);
}
use of okhttp3 in project okhttp-OkGo by jeasonlzy.
the class BaseRequest method getCall.
/** 获取同步call对象 */
public okhttp3.Call getCall() {
//构建请求体,返回call对象
RequestBody requestBody = generateRequestBody();
mRequest = generateRequest(wrapRequestBody(requestBody));
return generateCall(mRequest);
}
Aggregations