Java Code Examples for com.android.volley.Request#getBody()

The following examples show how to use com.android.volley.Request#getBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockHttpStack.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError {
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
Example 2
Source File: HurlStack.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
private static void addBodyIfExists(HttpURLConnection connection,
                Request<?> request) throws IOException, AuthFailureError {

    byte[] body = request.getBody();
    if (body != null) {
        if (VolleyLog.sDebug) {
            VolleyLog.v("Request url: %s\nBody: %s", request.getUrl(), new String(body, HTTP.UTF_8));
        }
        connection.setDoOutput(true);
        connection.addRequestProperty(HEADER_CONTENT_TYPE, request
                        .getBodyContentType());
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
    }
}
 
Example 3
Source File: FakeRequestQueue.java    From openshop.io-android with MIT License 6 votes vote down vote up
@Override
public Request add(Request request) {
    Timber.d("FakeRequestQueue is used");
    Timber.d("New request %s is added with priority %s", request.getUrl(), request.getPriority());
    try {
        if (request.getBody() == null) {
            Timber.d("Body is null");
        } else {
            Timber.d("Body: %s", new String(request.getBody()));
        }
    } catch (AuthFailureError e) {
        // cannot do anything
    }
    request.setShouldCache(false);
    return super.add(request);
}
 
Example 4
Source File: HttpClientStack.java    From android_tv_metro with Apache License 2.0 5 votes vote down vote up
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
Example 5
Source File: HttpClientStack.java    From okulus with Apache License 2.0 5 votes vote down vote up
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
Example 6
Source File: HttpClientStack.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
Example 7
Source File: HttpClientStack.java    From product-emm with Apache License 2.0 5 votes vote down vote up
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
Example 8
Source File: HttpClientStack.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
Example 9
Source File: HurlStack.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        connection.setDoOutput(true);
        connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType());
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
    }
}
 
Example 10
Source File: HurlStack.java    From product-emm with Apache License 2.0 5 votes vote down vote up
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        connection.setDoOutput(true);
        connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType());
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
    }
}
 
Example 11
Source File: HttpClientStack.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
Example 12
Source File: HttpClientStack.java    From jus with Apache License 2.0 5 votes vote down vote up
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
Example 13
Source File: HurlStack.java    From device-database with Apache License 2.0 5 votes vote down vote up
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        connection.setDoOutput(true);
        connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType());
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
    }
}
 
Example 14
Source File: HurlStack.java    From product-emm with Apache License 2.0 5 votes vote down vote up
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        connection.setDoOutput(true);
        connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType());
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
    }
}
 
Example 15
Source File: OkHttpStack.java    From android with MIT License 5 votes vote down vote up
private static RequestBody createRequestBody(Request r) throws AuthFailureError {
    byte[] body = r.getBody();
    if (body == null) {
        return null;
    }
    return RequestBody.create(MediaType.parse(r.getBodyContentType()), body);
}
 
Example 16
Source File: HurlStack.java    From volley with Apache License 2.0 5 votes vote down vote up
private void addBodyIfExists(HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        addBody(connection, request, body);
    }
}
 
Example 17
Source File: OkHttpStack.java    From CrossBow with Apache License 2.0 4 votes vote down vote up
private static RequestBody createRequestBody(Request r) throws AuthFailureError {
    final byte[] body = r.getBody();
    if (body == null) return null;

    return RequestBody.create(MediaType.parse(r.getBodyContentType()), body);
}
 
Example 18
Source File: OkHttpStack.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
private static RequestBody createRequestBody(Request r) throws AuthFailureError {
    final byte[] body = r.getBody();
    if (body == null) return null;

    return RequestBody.create(MediaType.parse(r.getBodyContentType()), body);
}
 
Example 19
Source File: OkHttpStack.java    From OkVolley with Apache License 2.0 4 votes vote down vote up
static void setConnectionParametersForRequest(com.squareup.okhttp.Request.Builder builder,
                                              Request<?> request) throws IOException, AuthFailureError {

    byte[] postBody = null;
    if (VolleyLog.DEBUG) {
        VolleyLog.d("request.method = %1$s", request.getMethod());
    }
    switch (request.getMethod()) {
        case Method.DEPRECATED_GET_OR_POST:
            // This is the deprecated way that needs to be handled for backwards compatibility.
            // If the request's post body is null, then the assumption is that the request is
            // GET.  Otherwise, it is assumed that the request is a POST.
            postBody = request.getBody();
            if (postBody != null) {
                // Prepare output. There is no need to set Content-Length explicitly,
                // since this is handled by HttpURLConnection using the size of the prepared
                // output stream.
                builder.post(RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody));
                if (VolleyLog.DEBUG) {
                    VolleyLog.d("RequestHeader: %1$s:%2$s", OkRequest.HEADER_CONTENT_TYPE, request.getPostBodyContentType());
                }
            } else {
                builder.get();
            }
            break;
        case Method.GET:
            // Not necessary to set the request method because connection defaults to GET but
            // being explicit here.
            builder.get();
            break;
        case Method.DELETE:
            builder.delete();
            break;
        case Method.POST:
            postBody = request.getBody();
            if (postBody == null) {
                builder.post(RequestBody.create(MediaType.parse(request.getBodyContentType()), ""));
            } else {
                builder.post(RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody));
            }
            if (VolleyLog.DEBUG) {
                VolleyLog.d("RequestHeader: %1$s:%2$s", OkRequest.HEADER_CONTENT_TYPE, request.getBodyContentType());
            }
            break;
        case Method.PUT:
            postBody = request.getBody();
            if (postBody == null) {
                builder.put(RequestBody.create(MediaType.parse(request.getBodyContentType()), ""));
            } else {
                builder.put(RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody));
            }
            if (VolleyLog.DEBUG) {
                VolleyLog.d("RequestHeader: %1$s:%2$s", OkRequest.HEADER_CONTENT_TYPE, request.getBodyContentType());
            }
            break;
        case Method.HEAD:
            builder.head();
            break;
        case Method.PATCH:
            postBody = request.getBody();
            if (postBody == null) {
                builder.patch(RequestBody.create(MediaType.parse(request.getBodyContentType()), ""));
            } else {
                builder.patch(RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody));
            }
            if (VolleyLog.DEBUG) {
                VolleyLog.d("RequestHeader: %1$s:%2$s", OkRequest.HEADER_CONTENT_TYPE, request.getBodyContentType());
            }
            break;
        default:
            throw new IllegalStateException("Unknown method type.");
    }


}
 
Example 20
Source File: HttpClientStack.java    From SaveVolley with Apache License 2.0 3 votes vote down vote up
/**
 * Volley 的 抽象请求 Request -> org.apache.http.client.methods.HttpEntityEnclosingRequestBase
 * 的封装过渡
 *
 * 即 Volley 的 抽象请求 Request -> Apache 请求的 封装过渡
 * 主要工作是 判断 Volley 的 抽象请求 Request 的 请求数据 赋值 给一个 org.apache.http.client.methods.HttpEntityEnclosingRequestBase
 * 作为其的 HttpEntityEnclosingRequestBase.HttpEntity 存在
 *
 * @param httpRequest httpRequest
 * @param request request
 * @throws AuthFailureError AuthFailureError
 */
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest, Request<?> request)
        throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}