use of okhttp3.Request.Builder in project MVCHelper by LuckyJayce.
the class PostFileMethod method buildRequset.
@Override
protected Request.Builder buildRequset(String url, Map<String, Object> params) {
MultipartBody.Builder builder = new MultipartBody.Builder();
if (params != null) {
for (Entry<String, ?> entry : params.entrySet()) {
builder.addFormDataPart(entry.getKey(), String.valueOf(entry.getValue()));
}
}
if (httpbodys != null) {
for (Entry<String, Data2<String, RequestBody>> entry : httpbodys.entrySet()) {
String key = entry.getKey();
Data2<String, RequestBody> body = entry.getValue();
builder.addFormDataPart(key, body.getValue1(), body.getValue2());
}
}
RequestBody formBody = builder.build();
if (listener != null) {
formBody = new CountingRequestBody(formBody, listener);
}
return new Request.Builder().url(url).post(formBody);
}
use of okhttp3.Request.Builder in project MVCHelper by LuckyJayce.
the class PostMethod method buildRequset.
@Override
protected Request.Builder buildRequset(String url, Map<String, Object> params) {
FormBody.Builder builder = new FormBody.Builder();
if (params != null) {
for (Entry<String, ?> entry : params.entrySet()) {
builder.add(entry.getKey(), String.valueOf(entry.getValue()));
}
}
RequestBody formBody = builder.build();
return new Request.Builder().url(url).post(formBody);
}
use of okhttp3.Request.Builder in project MVCHelper by LuckyJayce.
the class PutMethod method buildRequset.
@Override
protected Request.Builder buildRequset(String url, Map<String, Object> params) {
FormBody.Builder builder = new FormBody.Builder();
if (params != null) {
for (Entry<String, ?> entry : params.entrySet()) {
builder.add(entry.getKey(), String.valueOf(entry.getValue()));
}
}
RequestBody formBody = builder.build();
return new Request.Builder().url(url).put(formBody);
}
use of okhttp3.Request.Builder in project sonarqube by SonarSource.
the class OkHttpClientBuilder method build.
public OkHttpClient build() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.proxy(proxy);
if (connectTimeoutMs >= 0) {
builder.connectTimeout(connectTimeoutMs, TimeUnit.MILLISECONDS);
}
if (readTimeoutMs >= 0) {
builder.readTimeout(readTimeoutMs, TimeUnit.MILLISECONDS);
}
builder.addInterceptor(this::completeHeaders);
ConnectionSpec tls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).allEnabledTlsVersions().allEnabledCipherSuites().supportsTlsExtensions(true).build();
builder.connectionSpecs(asList(tls, ConnectionSpec.CLEARTEXT));
X509TrustManager trustManager = sslTrustManager != null ? sslTrustManager : systemDefaultTrustManager();
SSLSocketFactory sslFactory = sslSocketFactory != null ? sslSocketFactory : systemDefaultSslSocketFactory(trustManager);
builder.sslSocketFactory(sslFactory, trustManager);
return builder.build();
}
use of okhttp3.Request.Builder in project Parse-SDK-Android by ParsePlatform.
the class ParseOkHttpClientTest method testGetOkHttpRequestType.
//region testTransferRequest/Response
@Test
public void testGetOkHttpRequestType() throws IOException {
ParseOkHttpClient parseClient = new ParseOkHttpClient(10000, null);
ParseHttpRequest.Builder builder = new ParseHttpRequest.Builder();
builder.setUrl("http://www.parse.com");
// Get
ParseHttpRequest parseRequest = builder.setMethod(ParseHttpRequest.Method.GET).setBody(null).build();
Request okHttpRequest = parseClient.getRequest(parseRequest);
assertEquals(ParseHttpRequest.Method.GET.toString(), okHttpRequest.method());
// Post
parseRequest = builder.setMethod(ParseHttpRequest.Method.POST).setBody(new ParseByteArrayHttpBody("test", "application/json")).build();
okHttpRequest = parseClient.getRequest(parseRequest);
assertEquals(ParseHttpRequest.Method.POST.toString(), okHttpRequest.method());
// Delete
parseRequest = builder.setMethod(ParseHttpRequest.Method.DELETE).setBody(null).build();
okHttpRequest = parseClient.getRequest(parseRequest);
assertEquals(ParseHttpRequest.Method.DELETE.toString(), okHttpRequest.method());
// Put
parseRequest = builder.setMethod(ParseHttpRequest.Method.PUT).setBody(new ParseByteArrayHttpBody("test", "application/json")).build();
okHttpRequest = parseClient.getRequest(parseRequest);
assertEquals(ParseHttpRequest.Method.PUT.toString(), okHttpRequest.method());
}
Aggregations