Search in sources :

Example 1 with HttpParamsEntry

use of com.kymjs.rxvolley.toolbox.HttpParamsEntry in project yoo_home_Android by culturer.

the class OkHttpStack method performRequest.

@Override
public URLHttpResponse performRequest(Request<?> request, ArrayList<HttpParamsEntry> additionalHeaders) throws IOException {
    OkHttpClient client = mClient.clone();
    int timeoutMs = request.getTimeoutMs();
    client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.Request.Builder();
    okHttpRequestBuilder.url(request.getUrl());
    for (final HttpParamsEntry entry : request.getHeaders()) {
        okHttpRequestBuilder.addHeader(entry.k, entry.v);
    }
    for (final HttpParamsEntry entry : additionalHeaders) {
        okHttpRequestBuilder.addHeader(entry.k, entry.v);
    }
    setConnectionParametersForRequest(okHttpRequestBuilder, request);
    com.squareup.okhttp.Request okHttpRequest = okHttpRequestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();
    return responseFromConnection(okHttpResponse);
}
Also used : Response(com.squareup.okhttp.Response) URLHttpResponse(com.kymjs.rxvolley.http.URLHttpResponse) Call(com.squareup.okhttp.Call) OkHttpClient(com.squareup.okhttp.OkHttpClient) Request(com.kymjs.rxvolley.http.Request) HttpParamsEntry(com.kymjs.rxvolley.toolbox.HttpParamsEntry)

Example 2 with HttpParamsEntry

use of com.kymjs.rxvolley.toolbox.HttpParamsEntry in project yoo_home_Android by culturer.

the class HttpParams method getUrlParams.

public StringBuilder getUrlParams() {
    StringBuilder result = new StringBuilder();
    boolean isFirst = true;
    Collections.sort(urlParams);
    for (HttpParamsEntry entry : urlParams) {
        if (!isFirst) {
            result.append("&");
        } else {
            result.append("?");
            isFirst = false;
        }
        try {
            result.append(URLEncoder.encode(entry.k, CHARSET)).append("=").append(URLEncoder.encode(entry.v, CHARSET));
        } catch (UnsupportedEncodingException e) {
            result.append(entry.k).append("=").append(entry.v);
        }
    }
    return result;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpParamsEntry(com.kymjs.rxvolley.toolbox.HttpParamsEntry)

Example 3 with HttpParamsEntry

use of com.kymjs.rxvolley.toolbox.HttpParamsEntry in project yoo_home_Android by culturer.

the class OkHttpStack method performRequest.

@Override
public URLHttpResponse performRequest(Request<?> request, ArrayList<HttpParamsEntry> additionalHeaders) throws IOException {
    int timeoutMs = request.getTimeoutMs();
    OkHttpClient client = mClient.newBuilder().readTimeout(timeoutMs, TimeUnit.MILLISECONDS).connectTimeout(timeoutMs, TimeUnit.MILLISECONDS).writeTimeout(timeoutMs, TimeUnit.MILLISECONDS).build();
    okhttp3.Request.Builder okHttpRequestBuilder = new okhttp3.Request.Builder();
    okHttpRequestBuilder.url(request.getUrl());
    for (final HttpParamsEntry entry : request.getHeaders()) {
        okHttpRequestBuilder.addHeader(entry.k, entry.v);
    }
    for (final HttpParamsEntry entry : additionalHeaders) {
        okHttpRequestBuilder.addHeader(entry.k, entry.v);
    }
    setConnectionParametersForRequest(okHttpRequestBuilder, request);
    okhttp3.Request okHttpRequest = okHttpRequestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();
    return responseFromConnection(okHttpResponse);
}
Also used : Response(okhttp3.Response) URLHttpResponse(com.kymjs.rxvolley.http.URLHttpResponse) Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Request(com.kymjs.rxvolley.http.Request) HttpParamsEntry(com.kymjs.rxvolley.toolbox.HttpParamsEntry)

Example 4 with HttpParamsEntry

use of com.kymjs.rxvolley.toolbox.HttpParamsEntry in project yoo_home_Android by culturer.

the class FileRequest method getHeaders.

@Override
public ArrayList<HttpParamsEntry> getHeaders() {
    mHeaders.add(new HttpParamsEntry("Range", "bytes=" + mTemporaryFile.length() + "-"));
    mHeaders.add(new HttpParamsEntry("Accept-Encoding", "identity"));
    return mHeaders;
}
Also used : HttpParamsEntry(com.kymjs.rxvolley.toolbox.HttpParamsEntry)

Example 5 with HttpParamsEntry

use of com.kymjs.rxvolley.toolbox.HttpParamsEntry in project yoo_home_Android by culturer.

the class HttpParams method put.

/**
 * 添加文本参数
 */
public void put(final String key, final String value) {
    urlParams.add(new HttpParamsEntry(key, value));
    writeToOutputStream(key, value.getBytes(), TYPE_TEXT_CHARSET, BIT_ENCODING, "");
}
Also used : HttpParamsEntry(com.kymjs.rxvolley.toolbox.HttpParamsEntry)

Aggregations

HttpParamsEntry (com.kymjs.rxvolley.toolbox.HttpParamsEntry)9 Request (com.kymjs.rxvolley.http.Request)2 URLHttpResponse (com.kymjs.rxvolley.http.URLHttpResponse)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 FileRequest (com.kymjs.rxvolley.client.FileRequest)1 Call (com.squareup.okhttp.Call)1 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 Response (com.squareup.okhttp.Response)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Call (okhttp3.Call)1 OkHttpClient (okhttp3.OkHttpClient)1