Search in sources :

Example 66 with Response

use of com.squareup.okhttp.Response in project remusic by aa112901.

the class HttpUtil method postNetease.

public static void postNetease(Context context, String j) {
    try {
        String action = "https://music.163.com/weapi/login/";
        RequestBody formBody = new FormEncodingBuilder().add("params", "9NdyZTlp0Q/f1E1ora4tGM0uLYXqh7MD0mk7632ilWQvRDPZ02UkHrGFUccwW4HZYpacpPnmE+oMr/HI/vhuQvg8zYKgDP6NOaXG8nKDJpQTfOAiXT5KDrJOvb7ejSj/").add("encSeckey", "ae878167c394a959699c025a5c36043d0ae043c42d7f55fe4d1191c8ac9f3abe285b78c4a25ed6d9394a0ba0cb83a9a62de697199bd337f1de183bb07d6764a051495ea873ad615bb0a7e69f44d9168fc78ed1d61feb142ad06679dce58257ee9005756a18032ff499a4e24f7658bb59de2219f21f568301d43dba500e0c2d3b").build();
        String json = "{\"params\": \"9NdyZTlp0Q/f1E1ora4tGM0uLYXqh7MD0mk7632ilWQvRDPZ02UkHrGFUccwW4HZYpacpPnmE+oMr/HI/vhuQvg8zYKgDP6NOaXG8nKDJpQTfOAiXT5KDrJOvb7ejSj/\",  " + "\"encSecKey\": \"ae878167c394a959699c025a5c36043d0ae043c42d7f55fe4d1191c8ac9f3abe285b78c4a25ed6d9394a0ba0cb83a9a62de697199bd337f1de183bb07d6764a051495ea873ad615bb0a7e69f44d9168fc78ed1d61feb142ad06679dce58257ee9005756a18032ff499a4e24f7658bb59de2219f21f568301d43dba500e0c2d3b\"}";
        RequestBody requestBody = RequestBody.create(MediaType.parse("JSON"), json);
        Log.e("post", "p");
        Request request = new Request.Builder().url(action).header("Content-Type", "application/x-www-form-urlencoded").header("Host", "music.163.com").header("Cookie", "appver=1.5.0.75771").header("Referer", "http://music.163.com/").header("Connection", "keep-alive").header("Accept-Encoding", "gzip,deflate").header("Accept", "*/*").header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36").post(requestBody).build();
        mOkHttpClient.setCookieHandler(new CookieManager(new PersistentCookieStore(context.getApplicationContext()), CookiePolicy.ACCEPT_ALL));
        Response response = mOkHttpClient.newCall(request).execute();
        if (response.isSuccessful()) {
            Log.e("respose", response.body().string());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Response(com.squareup.okhttp.Response) Request(com.squareup.okhttp.Request) FormEncodingBuilder(com.squareup.okhttp.FormEncodingBuilder) CookieManager(java.net.CookieManager) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestBody(com.squareup.okhttp.RequestBody)

Example 67 with Response

use of com.squareup.okhttp.Response in project remusic by aa112901.

the class HttpUtil method getOut.

public static void getOut(final String url) {
    try {
        mOkHttpClient.setConnectTimeout(1000, TimeUnit.MINUTES);
        mOkHttpClient.setReadTimeout(1000, TimeUnit.MINUTES);
        Request request = new Request.Builder().url(url).build();
        Response response = mOkHttpClient.newCall(request).execute();
        if (response.isSuccessful()) {
            FileOutputStream fo = new FileOutputStream("/storage/emulated/0/" + "gedangein" + ".json");
            byte[] c = new byte[1024];
            while (response.body().source().read(c) != -1) {
                fo.write(c);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Response(com.squareup.okhttp.Response) FormEncodingBuilder(com.squareup.okhttp.FormEncodingBuilder) FileOutputStream(java.io.FileOutputStream) Request(com.squareup.okhttp.Request) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 68 with Response

use of com.squareup.okhttp.Response in project robovm by robovm.

the class Job method run.

@Override
public void run() {
    try {
        sendRequest();
        Response response = readResponse();
        responseReceiver.onResponse(response);
    } catch (IOException e) {
        responseReceiver.onFailure(new Failure.Builder().request(request).exception(e).build());
    } finally {
        connection.disconnect();
        dispatcher.finished(this);
    }
}
Also used : Response(com.squareup.okhttp.Response) IOException(java.io.IOException) Failure(com.squareup.okhttp.Failure)

Example 69 with Response

use of com.squareup.okhttp.Response in project AisenWeiBo by wangdan.

the class PictureSizeHttpUtility method doGet.

@Override
public <T> T doGet(HttpConfig config, Setting action, Params urlParams, Class<T> responseCls) throws TaskException {
    if (GlobalContext.getInstance() == null || SystemUtils.getNetworkType(GlobalContext.getInstance()) == SystemUtils.NetWorkType.none)
        return null;
    String url = urlParams.getParameter("path");
    PictureSize size = new PictureSize();
    size.setUrl(url);
    Request request = new Request.Builder().url(url).build();
    try {
        Response response = GlobalContext.getOkHttpClient().newCall(request).execute();
        if (!(response.code() == HttpURLConnection.HTTP_OK || response.code() == HttpURLConnection.HTTP_PARTIAL)) {
            throw new TaskException(String.valueOf(TaskException.TaskError.failIOError));
        } else {
            // 图片大小
            String header = response.header("Content-Length");
            int length = Integer.parseInt(header);
            size.setSize(length);
            SinaDB.getDB().insert(null, size);
            Logger.d(TAG, String.format("图片大小 %s", String.valueOf(size.getSize())));
        }
    } catch (Exception e) {
        throw new TaskException(String.valueOf(TaskException.TaskError.failIOError));
    }
    return (T) size;
}
Also used : Response(com.squareup.okhttp.Response) PictureSize(org.aisen.weibo.sina.support.bean.PictureSize) TaskException(org.aisen.android.network.task.TaskException) Request(com.squareup.okhttp.Request) TaskException(org.aisen.android.network.task.TaskException)

Example 70 with Response

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

the class HttpEngineReadResponseMethodInterceptor 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 {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
        if (statusCode) {
            // type check validate();
            Response response = ((UserResponseGetter) target)._$PINPOINT$_getUserResponse();
            if (response != null) {
                recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, response.code());
            }
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Response(com.squareup.okhttp.Response) UserResponseGetter(com.navercorp.pinpoint.plugin.okhttp.UserResponseGetter)

Aggregations

Response (com.squareup.okhttp.Response)109 Request (com.squareup.okhttp.Request)75 IOException (java.io.IOException)70 OkHttpClient (com.squareup.okhttp.OkHttpClient)31 RequestBody (com.squareup.okhttp.RequestBody)23 JSONException (org.json.JSONException)16 JSONObject (org.json.JSONObject)15 FormEncodingBuilder (com.squareup.okhttp.FormEncodingBuilder)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)10 ApiCallException (org.eyeseetea.malariacare.domain.exception.ApiCallException)10 Callback (com.squareup.okhttp.Callback)9 SocketTimeoutException (java.net.SocketTimeoutException)8 File (java.io.File)7 ShowException (org.eyeseetea.malariacare.views.ShowException)7 Buffer (okio.Buffer)6 MediaType (com.squareup.okhttp.MediaType)5 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 Call (com.squareup.okhttp.Call)4 ApiException (io.kubernetes.client.ApiException)4