use of com.squareup.okhttp.OkHttpClient in project pictureapp by EyeSeeTea.
the class BasicAuthenticator method executeCall.
/**
* Call to DHIS Server
*/
static Response executeCall(JSONObject data, String url, String method) throws IOException {
final String DHIS_URL = url;
OkHttpClient client = UnsafeOkHttpsClientFactory.getUnsafeOkHttpClient();
BasicAuthenticator basicAuthenticator = new BasicAuthenticator();
client.setAuthenticator(basicAuthenticator);
Request.Builder builder = new Request.Builder().header(basicAuthenticator.AUTHORIZATION_HEADER, basicAuthenticator.getCredentials()).url(DHIS_URL);
switch(method) {
case "POST":
RequestBody postBody = RequestBody.create(JSON, data.toString());
builder.post(postBody);
break;
case "PUT":
RequestBody putBody = RequestBody.create(JSON, data.toString());
builder.put(putBody);
break;
case "PATCH":
RequestBody patchBody = RequestBody.create(JSON, data.toString());
builder.patch(patchBody);
break;
case "GET":
builder.get();
break;
}
Request request = builder.build();
return client.newCall(request).execute();
}
use of com.squareup.okhttp.OkHttpClient in project weex-example by KalicyZhou.
the class DefaultWebSocketAdapter method connect.
@Override
public void connect(String url, @Nullable String protocol, EventListener listener) {
this.eventListener = listener;
OkHttpClient okHttpClient = new OkHttpClient();
Request.Builder builder = new Request.Builder();
if (protocol != null) {
builder.addHeader(HEADER_SEC_WEBSOCKET_PROTOCOL, protocol);
}
builder.url(url);
WebSocketCall.create(okHttpClient, builder.build()).enqueue(new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Request request, Response response) throws IOException {
ws = webSocket;
eventListener.onOpen();
}
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
eventListener.onMessage(payload.readUtf8());
payload.close();
}
@Override
public void onPong(Buffer payload) {
}
@Override
public void onClose(int code, String reason) {
eventListener.onClose(code, reason, true);
}
@Override
public void onFailure(IOException e) {
e.printStackTrace();
if (e instanceof EOFException) {
eventListener.onClose(WebSocketCloseCodes.CLOSE_NORMAL.getCode(), WebSocketCloseCodes.CLOSE_NORMAL.name(), true);
} else {
eventListener.onError(e.getMessage());
}
}
});
}
use of com.squareup.okhttp.OkHttpClient in project weex-example by KalicyZhou.
the class HotRefreshManager method connect.
public boolean connect(String url) {
OkHttpClient httpClient = new OkHttpClient();
Request request = new Request.Builder().url(url).addHeader("sec-websocket-protocol", "echo-protocol").build();
WebSocketCall.create(httpClient, request).enqueue(new WXWebSocketListener(url));
return true;
}
use of com.squareup.okhttp.OkHttpClient in project bdcodehelper by boredream.
the class AppKeeper method initGlide.
/**
* 图片加载框架Glide,使用OkHttp处理网络请求
*/
private static void initGlide(Application app) {
OkHttpClient okHttpClient = BaseHttpRequest.getHttpClient();
Glide.get(app).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient));
}
use of com.squareup.okhttp.OkHttpClient in project dropbox-sdk-java by dropbox.
the class OkHttpRequestor method defaultOkHttpClient.
/**
* Returns an {@code OkHttpClient} instance with the default settings for this SDK.
*/
public static OkHttpClient defaultOkHttpClient() {
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.setReadTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.setWriteTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
// enables certificate pinning
client.setSslSocketFactory(SSLConfig.getSSLSocketFactory());
return client;
}
Aggregations