本文整理汇总了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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}