Search in sources :

Example 6 with Request

use of com.squareup.okhttp.Request in project fresco by facebook.

the class OkHttpNetworkFetcher method fetch.

@Override
public void fetch(final OkHttpNetworkFetchState fetchState, final Callback callback) {
    fetchState.submitTime = SystemClock.uptimeMillis();
    final Uri uri = fetchState.getUri();
    try {
        Request request = new Request.Builder().cacheControl(new CacheControl.Builder().noStore().build()).url(uri.toString()).get().build();
        fetchWithRequest(fetchState, callback, request);
    } catch (Exception e) {
        // handle error while creating the request
        callback.onFailure(e);
    }
}
Also used : Request(com.squareup.okhttp.Request) Uri(android.net.Uri) IOException(java.io.IOException)

Example 7 with Request

use of com.squareup.okhttp.Request in project LookLook by xinghongfei.

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 8 with Request

use of com.squareup.okhttp.Request in project PocketHub by pockethub.

the class RawCommentFragment method onActivityResult.

@Override
public void onActivityResult(final int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_SELECT_PHOTO && resultCode == Activity.RESULT_OK) {
        showProgressIndeterminate(R.string.loading);
        ImageBinPoster.post(getActivity(), data.getData(), new Callback() {

            @Override
            public void onFailure(Request request, IOException e) {
                dismissProgress();
                showImageError();
            }

            @Override
            public void onResponse(Response response) throws IOException {
                dismissProgress();
                if (response.isSuccessful()) {
                    insertImage(ImageBinPoster.getUrl(response.body().string()));
                } else {
                    showImageError();
                }
            }
        });
    }
}
Also used : Response(com.squareup.okhttp.Response) Callback(com.squareup.okhttp.Callback) Request(com.squareup.okhttp.Request) IOException(java.io.IOException)

Example 9 with Request

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

the class ProtoClient method request.

/**
 * Generic protocol buffer based HTTP request. Not intended for general consumption, but public
 * for advance use cases.
 *
 * @param builder The appropriate Builder for the object receveived from the request.
 * @param method The HTTP method (e.g. GET) for this request.
 * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
 * @param body The body to send with the request (optional)
 * @param apiVersion The 'apiVersion' to use when encoding, required if body is non-null, ignored
 *     otherwise.
 * @param kind The 'kind' field to use when encoding, required if body is non-null, ignored
 *     otherwise.
 * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
 */
public <T extends Message> ObjectOrStatus<T> request(T.Builder builder, String path, String method, T body, String apiVersion, String kind) throws ApiException, IOException {
    HashMap<String, String> headers = new HashMap<>();
    headers.put("Content-Type", MEDIA_TYPE);
    headers.put("Accept", MEDIA_TYPE);
    String[] localVarAuthNames = new String[] { "BearerToken" };
    Request request = apiClient.buildRequest(path, method, new ArrayList<Pair>(), new ArrayList<Pair>(), null, headers, new HashMap<String, Object>(), localVarAuthNames, null);
    if (body != null) {
        byte[] bytes = encode(body, apiVersion, kind);
        switch(method) {
            case "POST":
                request = request.newBuilder().post(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
                break;
            case "PUT":
                request = request.newBuilder().put(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
                break;
            case "PATCH":
                request = request.newBuilder().patch(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
                break;
            default:
                throw new ApiException("Unknown proto client API method: " + method);
        }
    }
    Response resp = apiClient.getHttpClient().newCall(request).execute();
    Unknown u = parse(resp.body().byteStream());
    resp.body().close();
    if (u.getTypeMeta().getApiVersion().equals("v1") && u.getTypeMeta().getKind().equals("Status")) {
        Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();
        return new ObjectOrStatus(null, status);
    }
    return new ObjectOrStatus((T) builder.mergeFrom(u.getRaw()).build(), null);
}
Also used : Status(io.kubernetes.client.proto.Meta.Status) HashMap(java.util.HashMap) Request(com.squareup.okhttp.Request) Response(com.squareup.okhttp.Response) Unknown(io.kubernetes.client.proto.Runtime.Unknown)

Example 10 with Request

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

the class DefHttpUtility method doGet.

@Override
public <T> T doGet(HttpConfig config, Setting action, Params urlParams, Class<T> responseCls) throws TaskException {
    Request.Builder builder = createRequestBuilder(config, action, urlParams, "Get");
    Request request = builder.build();
    return executeRequest(request, responseCls, action, "Get");
}
Also used : 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