當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。