Search in sources :

Example 41 with Request

use of com.squareup.okhttp.Request in project SimpleNews by liuling07.

the class OkHttpUtils method getRequest.

private void getRequest(String url, final ResultCallback callback) {
    final Request request = new Request.Builder().url(url).build();
    deliveryResult(callback, request);
}
Also used : FormEncodingBuilder(com.squareup.okhttp.FormEncodingBuilder) Request(com.squareup.okhttp.Request)

Example 42 with Request

use of com.squareup.okhttp.Request in project pinpoint by naver.

the class HttpEngineSendRequestMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!validate(target)) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
        // clear attachment.
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        final Object attachment = getAttachment(invocation);
        if (attachment != null) {
            invocation.removeAttachment();
        }
        // typeCheck validate();
        final Request request = ((UserRequestGetter) target)._$PINPOINT$_getUserRequest();
        if (request != null) {
            this.clientRequestRecorder.record(recorder, request, throwable);
            this.cookieRecorder.record(recorder, request, throwable);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) UserRequestGetter(com.navercorp.pinpoint.plugin.okhttp.v2.UserRequestGetter) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Request(com.squareup.okhttp.Request)

Example 43 with Request

use of com.squareup.okhttp.Request in project grpc-java by grpc.

the class OkHttpClientTransport method createHttpProxyRequest.

private Request createHttpProxyRequest(InetSocketAddress address, String proxyUsername, String proxyPassword) {
    HttpUrl tunnelUrl = new HttpUrl.Builder().scheme("https").host(address.getHostName()).port(address.getPort()).build();
    Request.Builder request = new Request.Builder().url(tunnelUrl).header("Host", tunnelUrl.host() + ":" + tunnelUrl.port()).header("User-Agent", userAgent);
    // If we have proxy credentials, set them right away
    if (proxyUsername != null && proxyPassword != null) {
        request.header("Proxy-Authorization", Credentials.basic(proxyUsername, proxyPassword));
    }
    return request.build();
}
Also used : Request(com.squareup.okhttp.Request) HttpUrl(com.squareup.okhttp.HttpUrl)

Example 44 with Request

use of com.squareup.okhttp.Request in project MusicDNA by harjot-oberai.

the class ViewLyrics method search.

private static ArrayList<Lyrics> search(String searchQuery) throws IOException, ParserConfigurationException, SAXException, NoSuchAlgorithmException {
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(10, TimeUnit.SECONDS);
    client.setReadTimeout(30, TimeUnit.SECONDS);
    RequestBody body = RequestBody.create(MediaType.parse("application/text"), assembleQuery(searchQuery.getBytes("UTF-8")));
    Request request = new Request.Builder().header("User-Agent", clientUserAgent).post(body).url(url).build();
    Response response = client.newCall(request).execute();
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.body().byteStream(), "ISO_8859_1"));
    // Get full result
    StringBuilder builder = new StringBuilder();
    char[] buffer = new char[8192];
    int read;
    while ((read = rd.read(buffer, 0, buffer.length)) > 0) {
        builder.append(buffer, 0, read);
    }
    String full = builder.toString();
    // Decrypt, parse, store, and return the result list
    return parseResultXML(decryptResultXML(full));
}
Also used : Response(com.squareup.okhttp.Response) OkHttpClient(com.squareup.okhttp.OkHttpClient) InputStreamReader(java.io.InputStreamReader) Request(com.squareup.okhttp.Request) BufferedReader(java.io.BufferedReader) RequestBody(com.squareup.okhttp.RequestBody)

Example 45 with Request

use of com.squareup.okhttp.Request in project MusicDNA by harjot-oberai.

the class Net method getUrlAsString.

public static String getUrlAsString(URL paramURL) throws IOException {
    Request request = new Request.Builder().header("User-Agent", USER_AGENT).url(paramURL).build();
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(10, TimeUnit.SECONDS);
    Response response = client.newCall(request).execute();
    return response.body().string();
}
Also used : Response(com.squareup.okhttp.Response) OkHttpClient(com.squareup.okhttp.OkHttpClient) Request(com.squareup.okhttp.Request)

Aggregations

Request (com.squareup.okhttp.Request)111 Response (com.squareup.okhttp.Response)75 IOException (java.io.IOException)60 OkHttpClient (com.squareup.okhttp.OkHttpClient)37 RequestBody (com.squareup.okhttp.RequestBody)30 FormEncodingBuilder (com.squareup.okhttp.FormEncodingBuilder)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)12 File (java.io.File)11 Callback (com.squareup.okhttp.Callback)10 InputStream (java.io.InputStream)7 Buffer (okio.Buffer)6 HttpUrl (com.squareup.okhttp.HttpUrl)5 MediaType (com.squareup.okhttp.MediaType)5 SocketTimeoutException (java.net.SocketTimeoutException)5 HashMap (java.util.HashMap)5 Call (com.squareup.okhttp.Call)4 ResponseBody (com.squareup.okhttp.ResponseBody)4 FileOutputStream (java.io.FileOutputStream)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3