okhttp3.RequestBody.contentType()方法的使用及代码示例

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

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

RequestBody.contentType介绍

[英]Returns the Content-Type header for this body.
[中]

代码示例

代码示例来源:origin: square/okhttp

@Override public MediaType contentType() {
 return body.contentType();
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

/** 重写调用实际的响应体的contentType */
@Override
public MediaType contentType() {
  return requestBody.contentType();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public MediaType contentType() {
  return requestBody.contentType();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public MediaType contentType() {
  return body.contentType();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public MediaType contentType() {
  return requestBody.contentType();
}

代码示例来源:origin: JessYanCoding/ProgressManager

@Override
public MediaType contentType() {
  return mDelegate.contentType();
}

代码示例来源:origin: Rukey7/MvpApp

@NonNull
private static String _parseParams(RequestBody body, Buffer requestBuffer) throws UnsupportedEncodingException {
  if (body.contentType() != null && !body.contentType().toString().contains("multipart")) {
    return URLDecoder.decode(requestBuffer.readUtf8(), "UTF-8");
  }
  return "null";
}

代码示例来源:origin: pinguo-zhouwei/MZBannerView

private boolean canInjectIntoBody(Request request) {
  if (request == null) {
    return false;
  }
  if (!TextUtils.equals(request.method(), "POST")) {
    return false;
  }
  RequestBody body = request.body();
  if (body == null) {
    return false;
  }
  MediaType mediaType = body.contentType();
  if (mediaType == null) {
    return false;
  }
  if (!TextUtils.equals(mediaType.subtype(), "x-www-form-urlencoded")) {
    return false;
  }
  return true;
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

private void bodyToString(Request request) {
    try {
      Request copy = request.newBuilder().build();
      RequestBody body = copy.body();
      if (body == null) return;
      Buffer buffer = new Buffer();
      body.writeTo(buffer);
      Charset charset = getCharset(body.contentType());
      log("\tbody:" + buffer.readString(charset));
    } catch (Exception e) {
      OkLogger.printStackTrace(e);
    }
  }
}

代码示例来源:origin: square/okhttp

MediaType contentType = body.contentType();
if (contentType != null) {
 requestBuilder.header("Content-Type", contentType.toString());

代码示例来源:origin: JessYanCoding/MVPArms

/**
 * 解析请求服务器的请求参数
 *
 * @param request {@link Request}
 * @return 解析后的请求信息
 * @throws UnsupportedEncodingException
 */
public static String parseParams(Request request) throws UnsupportedEncodingException {
  try {
    RequestBody body = request.newBuilder().build().body();
    if (body == null) return "";
    Buffer requestbuffer = new Buffer();
    body.writeTo(requestbuffer);
    Charset charset = Charset.forName("UTF-8");
    MediaType contentType = body.contentType();
    if (contentType != null) {
      charset = contentType.charset(charset);
    }
    String json = requestbuffer.readString(charset);
    if (UrlEncoderUtils.hasUrlEncoded(json)) {
      json = URLDecoder.decode(json, convertCharset(charset));
    }
    return CharacterHandler.jsonFormat(json);
  } catch (IOException e) {
    e.printStackTrace();
    return "{\"error\": \"" + e.getMessage() + "\"}";
  }
}

代码示例来源:origin: JessYanCoding/MVPArms

if (request.body() != null && isParseable(request.body().contentType())) {
  mPrinter.printJsonRequest(request, parseParams(request));
} else {

代码示例来源:origin: AsyncHttpClient/async-http-client

/**
 * Converts retrofit request to async-http-client request.
 *
 * @param request retrofit request
 * @return async-http-client request.
 */
@SneakyThrows
protected org.asynchttpclient.Request createRequest(@NonNull Request request) {
 // create async-http-client request builder
 val requestBuilder = new RequestBuilder(request.method());
 // request uri
 requestBuilder.setUrl(request.url().toString());
 // set headers
 val headers = request.headers();
 headers.names().forEach(name -> requestBuilder.setHeader(name, headers.values(name)));
 // set request body
 val body = request.body();
 if (body != null && body.contentLength() > 0) {
  if (body.contentType() != null) {
   requestBuilder.setHeader(HttpHeaderNames.CONTENT_TYPE, body.contentType().toString());
  }
  // write body to buffer
  val okioBuffer = new Buffer();
  body.writeTo(okioBuffer);
  requestBuilder.setBody(okioBuffer.readByteArray());
 }
 // customize the request builder (external customizer can change the request url for example)
 runConsumers(this.requestCustomizers, requestBuilder);
 return requestBuilder.build();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void upload() throws IOException {
 ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
 settings.setProperty(SONAR_TELEMETRY_URL.getKey(), TELEMETRY_URL);
 underTest.start();
 underTest.upload(JSON);
 verify(okHttpClient).newCall(requestCaptor.capture());
 Request request = requestCaptor.getValue();
 assertThat(request.method()).isEqualTo("POST");
 assertThat(request.body().contentType()).isEqualTo(MediaType.parse("application/json; charset=utf-8"));
 Buffer body = new Buffer();
 request.body().writeTo(body);
 assertThat(body.readUtf8()).isEqualTo(JSON);
 assertThat(request.url().toString()).isEqualTo(TELEMETRY_URL);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void opt_out() throws IOException {
  ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
  settings.setProperty(SONAR_TELEMETRY_URL.getKey(), TELEMETRY_URL);
  underTest.start();

  underTest.optOut(JSON);

  verify(okHttpClient).newCall(requestCaptor.capture());
  Request request = requestCaptor.getValue();
  assertThat(request.method()).isEqualTo("DELETE");
  assertThat(request.body().contentType()).isEqualTo(MediaType.parse("application/json; charset=utf-8"));
  Buffer body = new Buffer();
  request.body().writeTo(body);
  assertThat(body.readUtf8()).isEqualTo(JSON);
  assertThat(request.url().toString()).isEqualTo(TELEMETRY_URL);
 }
}

代码示例来源:origin: square/okhttp

if (requestBody.contentType() != null) {
 logger.log("Content-Type: " + requestBody.contentType());
MediaType contentType = requestBody.contentType();
if (contentType != null) {
 charset = contentType.charset(UTF8);

代码示例来源:origin: web3j/web3j

protected void verifyResult(String expected) throws Exception {
  RequestBody requestBody = requestInterceptor.getRequestBody();
  assertNotNull(requestBody);
  assertThat(requestBody.contentType(), is(HttpService.JSON_MEDIA_TYPE));
  Buffer buffer = new Buffer();
  requestBody.writeTo(buffer);
  assertThat(replaceRequestId(buffer.readUtf8()), is(replaceRequestId(expected)));
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

MediaType contentType = body.contentType();
if (contentType != null) {
 requestBuilder.header("Content-Type", contentType.toString());

代码示例来源:origin: jeasonlzy/okhttp-OkGo

if (requestBody.contentType() != null) {
  log("\tContent-Type: " + requestBody.contentType());
if (isPlaintext(requestBody.contentType())) {
  bodyToString(request);
} else {

代码示例来源:origin: square/okhttp

MediaType contentType = body.contentType();
if (contentType != null) {
 sink.writeUtf8("Content-Type: ")

相关文章

微信公众号

最新文章

更多