com.android.volley.Request.getBody()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中com.android.volley.Request.getBody方法的一些代码示例,展示了Request.getBody的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getBody方法的具体详情如下:
包路径:com.android.volley.Request
类名称:Request
方法名:getBody

Request.getBody介绍

[英]Returns the raw POST or PUT body to be sent.

By default, the body consists of the request parameters in application/x-www-form-urlencoded format. When overriding this method, consider overriding #getBodyContentType() as well to match the new body format.
[中]返回要发送的原始邮件或放置正文。
默认情况下,正文由application/x-www-form-urlencoded格式的请求参数组成。当重写此方法时,请考虑重写γ- GoByDyCytType(),以匹配新的体格式。

代码示例

代码示例来源:origin: chentao0707/SimplifyReader

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);
  }
}

代码示例来源:origin: chentao0707/SimplifyReader

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();
    }
  }
}

代码示例来源:origin: mcxiaoke/android-volley

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();
    }
  }
}

代码示例来源:origin: mcxiaoke/android-volley

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);
  }
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

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();
    }
  }
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

/**
 * 如果request的请求体不为空,进行设置请求体信息
 * @param httpRequest
 * @param request
 * @throws 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);
  }
}

代码示例来源:origin: chentao0707/SimplifyReader

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);
  }
}

代码示例来源:origin: mcxiaoke/android-volley

@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;
  }
}

代码示例来源:origin: flipkart-incubator/okhttp-stats

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);
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

@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;
  }
}

代码示例来源:origin: avluis/Hentoid

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);
}

代码示例来源:origin: cat9/EasyVolley

private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
    Request<?> request) throws AuthFailureError {
  HttpEntity entity = request.getBody();
  if (entity != null) {
    httpRequest.setEntity(entity);
  }
}

代码示例来源:origin: com.mcxiaoke.volley/library

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();
    }
  }
}

代码示例来源:origin: MewX/light-novel-library_Wenku8_Android

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);
  }
}

代码示例来源:origin: MewX/light-novel-library_Wenku8_Android

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();
    }
  }
}

代码示例来源:origin: com.mcxiaoke.volley/library

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);
  }
}

代码示例来源:origin: tazimete/android-app-food-delivery-system

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();
    }
  }
}

代码示例来源:origin: xuningjack/AndroidNet

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();
    }
  }
}

代码示例来源:origin: panxw/android-volley-manager

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();
  }
}

代码示例来源:origin: cat9/EasyVolley

private static void addBodyIfExists(HttpURLConnection connection, Request<?> request)
      throws IOException, AuthFailureError {
    HttpEntity body = request.getBody();
    if (body != null) {
      connection.setDoOutput(true);
      connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType());
      DataOutputStream out = new DataOutputStream(connection.getOutputStream());
      body.writeTo(out);
      out.close();
    }
  }
}

相关文章

微信公众号

最新文章

更多