当前位置: 首页>>代码示例>>Java>>正文


Java Request.getPostBody方法代码示例

本文整理汇总了Java中com.android.volley.Request.getPostBody方法的典型用法代码示例。如果您正苦于以下问题:Java Request.getPostBody方法的具体用法?Java Request.getPostBody怎么用?Java Request.getPostBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.volley.Request的用法示例。


在下文中一共展示了Request.getPostBody方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: switch

import com.android.volley.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
/* package */ static void setConnectionParametersForRequest(HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    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.
            byte[] postBody = request.getPostBody();
            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.
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.write(postBody);
                out.close();
            }
            break;
        case Method.GET:
            // Not necessary to set the request method because connection defaults to GET but
            // being explicit here.
            connection.setRequestMethod("GET");
            break;
        case Method.DELETE:
            connection.setRequestMethod("DELETE");
            break;
        case Method.POST:
            connection.setRequestMethod("POST");
            addBodyIfExists(connection, request);
            break;
        case Method.PUT:
            connection.setRequestMethod("PUT");
            addBodyIfExists(connection, request);
            break;
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:HanyeeWang,项目名称:GeekZone,代码行数:41,代码来源:BaseStack.java

示例2: setConnectionParametersForRequest

import com.android.volley.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private static void setConnectionParametersForRequest(okhttp3.Request.Builder builder, Request<?> request)
        throws IOException, AuthFailureError {
    switch (request.getMethod()) {
        case Request.Method.DEPRECATED_GET_OR_POST:
            // Ensure backwards compatibility.  Volley assumes a request with a null body is a GET.
            byte[] postBody = request.getPostBody();
            if (postBody != null) {
                builder.post(RequestBody.create(MediaType.parse(request.getPostBodyContentType()), postBody));
            }
            break;
        case Request.Method.GET:
            builder.get();
            break;
        case Request.Method.DELETE:
            builder.delete();
            break;
        case Request.Method.POST:
            builder.post(createRequestBody(request));
            break;
        case Request.Method.PUT:
            builder.put(createRequestBody(request));
            break;
        case Request.Method.HEAD:
            builder.head();
            break;
        case Request.Method.OPTIONS:
            builder.method("OPTIONS", null);
            break;
        case Request.Method.TRACE:
            builder.method("TRACE", null);
            break;
        case Request.Method.PATCH:
            builder.patch(createRequestBody(request));
            break;
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:HanyeeWang,项目名称:GeekZone,代码行数:40,代码来源:OkHttpStack.java

示例3: switch

import com.android.volley.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
/* package */ static void setConnectionParametersForRequest(HttpURLConnection connection,
        Request<?> request) throws IOException, AuthFailureError {
    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.
            byte[] postBody = request.getPostBody();
            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.
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                connection.addRequestProperty(HEADER_CONTENT_TYPE,
                        request.getPostBodyContentType());
                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.write(postBody);
                out.close();
            }
            break;
        case Method.GET:
            // Not necessary to set the request method because connection defaults to GET but
            // being explicit here.
            connection.setRequestMethod("GET");
            break;
        case Method.DELETE:
            connection.setRequestMethod("DELETE");
            break;
        case Method.POST:
            connection.setRequestMethod("POST");
            addBodyIfExists(connection, request);
            break;
        case Method.PUT:
            connection.setRequestMethod("PUT");
            addBodyIfExists(connection, request);
            break;
        case Method.HEAD:
            connection.setRequestMethod("HEAD");
            break;
        case Method.OPTIONS:
            connection.setRequestMethod("OPTIONS");
            break;
        case Method.TRACE:
            connection.setRequestMethod("TRACE");
            break;
        case Method.PATCH:
            connection.setRequestMethod("PATCH");
            addBodyIfExists(connection, request);
            break;
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:56,代码来源:HurlStack.java

示例4: switch

import com.android.volley.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private static void setConnectionParametersForRequest
        (com.squareup.okhttp.Request.Builder builder, Request<?> request)
        throws IOException, AuthFailureError {
    switch (request.getMethod()) {
        case Request.Method.DEPRECATED_GET_OR_POST:
            // Ensure backwards compatibility.
            // Volley assumes a request with a null body is a GET.
            byte[] postBody = request.getPostBody();

            if (postBody != null) {
                builder.post(RequestBody.create
                        (MediaType.parse(request.getPostBodyContentType()), postBody));
            }
            break;

        case Request.Method.GET:
            builder.get();
            break;

        case Request.Method.DELETE:
            builder.delete();
            break;

        case Request.Method.POST:
            builder.post(createRequestBody(request));
            break;

        case Request.Method.PUT:
            builder.put(createRequestBody(request));
            break;

        case Request.Method.HEAD:
            builder.head();
            break;

        case Request.Method.OPTIONS:
            builder.method("OPTIONS", null);
            break;

        case Request.Method.TRACE:
            builder.method("TRACE", null);
            break;

        case Request.Method.PATCH:
            builder.patch(createRequestBody(request));
            break;

        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:wangzhaosheng,项目名称:publicProject,代码行数:53,代码来源:OkHttpStack.java

示例5: setConnectionParametersForRequest

import com.android.volley.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void setConnectionParametersForRequest(okhttp3.Request.Builder builder, Request<?> request)
        throws IOException, AuthFailureError {
    switch (request.getMethod()) {
        case Request.Method.DEPRECATED_GET_OR_POST:
            byte[] postBody = request.getPostBody();
            if (postBody != null) {
                builder.post(okhttp3.RequestBody.create
                        (MediaType.parse(request.getPostBodyContentType()), postBody));
            } else {
                builder.get();
            }
            break;

        case Request.Method.GET:
            builder.get();
            break;

        case Request.Method.DELETE:
            builder.delete();
            break;

        case Request.Method.POST:
            builder.post(createRequestBody(request));
            break;

        case Request.Method.PUT:
            builder.put(createRequestBody(request));
            break;

        case Request.Method.HEAD:
            builder.head();
            break;

        case Request.Method.OPTIONS:
            builder.method("OPTIONS", null);
            break;

        case Request.Method.TRACE:
            builder.method("TRACE", null);
            break;

        case Request.Method.PATCH:
            builder.patch(createRequestBody(request));
            break;

        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:51,代码来源:OkHttp3Stack.java

示例6: switch

import com.android.volley.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
/* package */ static void setConnectionParametersForRequest(HttpURLConnection connection,
        Request<?> request) throws IOException, AuthFailureError {
    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.
            byte[] postBody = request.getPostBody();
            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.
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                connection.addRequestProperty(HEADER_CONTENT_TYPE,
                        request.getPostBodyContentType());
                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.write(postBody);
                out.close();
            }
            break;
        case Method.GET:
            // Not necessary to set the request method because connection defaults to GET but
            // being explicit here.
            connection.setRequestMethod("GET");
            break;
        case Method.DELETE:
            connection.setRequestMethod("DELETE");
            break;
        case Method.POST:
            connection.setRequestMethod("POST");
            addBodyIfExists(connection, request);
            break;
        case Method.PUT:
            connection.setRequestMethod("PUT");
            addBodyIfExists(connection, request);
            break;
        case Method.HEAD:
            connection.setRequestMethod("HEAD");
            break;
        case Method.OPTIONS:
            connection.setRequestMethod("OPTIONS");
            break;
        case Method.TRACE:
            connection.setRequestMethod("TRACE");
            break;
        case Method.PATCH:
            addBodyIfExists(connection, request);
            connection.setRequestMethod("PATCH");
            break;
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:56,代码来源:HurlStack.java

示例7: setConnectionParametersForRequest

import com.android.volley.Request; //导入方法依赖的package包/类
private boolean setConnectionParametersForRequest(StethoURLConnectionManager connectionManager, HttpURLConnection connection,
                                              Request<?> request) throws IOException, AuthFailureError {
    switch (request.getMethod()) {
        case Request.Method.DEPRECATED_GET_OR_POST:
            byte[] postBody = request.getPostBody();
            if (postBody != null) {
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                connection.addRequestProperty("Content-Type", request.getPostBodyContentType());

                preConnect(connectionManager, connection, null);

                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.write(postBody);
                out.close();
            }
            return true;
        case Request.Method.GET:
            connection.setRequestMethod("GET");
            return false;
        case Request.Method.DELETE:
            connection.setRequestMethod("DELETE");
            return false;
        case Request.Method.POST:
            connection.setRequestMethod("POST");
            return addBodyIfExists(connectionManager, connection, request);
        case Request.Method.PUT:
            connection.setRequestMethod("PUT");
            return addBodyIfExists(connectionManager, connection, request);
        case Request.Method.HEAD:
            connection.setRequestMethod("HEAD");
            return false;
        case Request.Method.OPTIONS:
            connection.setRequestMethod("OPTIONS");
            return false;
        case Request.Method.TRACE:
            connection.setRequestMethod("TRACE");
            return false;
        case Request.Method.PATCH:
            connection.setRequestMethod("PATCH");
            return addBodyIfExists(connectionManager, connection, request);
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:DLKanth,项目名称:Stetho-Volley,代码行数:46,代码来源:StethoVolleyStack.java

示例8: setConnectionParametersForRequest

import com.android.volley.Request; //导入方法依赖的package包/类
static void setConnectionParametersForRequest(HttpURLConnection connection, Request<?>
        request) throws IOException, AuthFailureError {
    switch (request.getMethod()) {
        case -1:
            byte[] postBody = request.getPostBody();
            if (postBody != null) {
                connection.setDoOutput(true);
                connection.setRequestMethod(Constants.HTTP_POST);
                connection.addRequestProperty("Content-Type", request.getPostBodyContentType());
                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.write(postBody);
                out.close();
                return;
            }
            return;
        case 0:
            connection.setRequestMethod("GET");
            return;
        case 1:
            connection.setRequestMethod(Constants.HTTP_POST);
            addBodyIfExists(connection, request);
            return;
        case 2:
            connection.setRequestMethod("PUT");
            addBodyIfExists(connection, request);
            return;
        case 3:
            connection.setRequestMethod(HttpDelete.METHOD_NAME);
            addBodyIfExists(connection, request);
            return;
        case 4:
            connection.setRequestMethod(HTTP.HEAD);
            return;
        case 5:
            connection.setRequestMethod("OPTIONS");
            return;
        case 6:
            connection.setRequestMethod("TRACE");
            return;
        case 7:
            connection.setRequestMethod("PATCH");
            addBodyIfExists(connection, request);
            return;
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:48,代码来源:MyHttpStack.java

示例9: setConnectionParametersForRequest

import com.android.volley.Request; //导入方法依赖的package包/类
static void setConnectionParametersForRequest(HttpURLConnection connection, Request<?> request) throws IOException, AuthFailureError {
    switch (request.getMethod()) {
        case -1:
            byte[] postBody = request.getPostBody();
            if (postBody != null) {
                connection.setDoOutput(true);
                connection.setRequestMethod(Constants.HTTP_POST);
                connection.addRequestProperty("Content-Type", request.getPostBodyContentType());
                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.write(postBody);
                out.close();
                return;
            }
            return;
        case 0:
            connection.setRequestMethod("GET");
            return;
        case 1:
            connection.setRequestMethod(Constants.HTTP_POST);
            addBodyIfExists(connection, request);
            return;
        case 2:
            connection.setRequestMethod("PUT");
            addBodyIfExists(connection, request);
            return;
        case 3:
            connection.setRequestMethod(HttpDelete.METHOD_NAME);
            return;
        case 4:
            connection.setRequestMethod(HTTP.HEAD);
            return;
        case 5:
            connection.setRequestMethod("OPTIONS");
            return;
        case 6:
            connection.setRequestMethod("TRACE");
            return;
        case 7:
            connection.setRequestMethod("PATCH");
            addBodyIfExists(connection, request);
            return;
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:46,代码来源:HurlStack.java


注:本文中的com.android.volley.Request.getPostBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。