搜尋

首頁  >  問答  >  主體

java - 请问OkHttp 3如何设置post请求的编码呢?

这是create方法的源码:

public static RequestBody create(MediaType contentType, String content) {
    Charset charset = Util.UTF_8;
    if (contentType != null) {
      charset = contentType.charset();
      if (charset == null) {
        charset = Util.UTF_8;
        contentType = MediaType.parse(contentType + "; charset=utf-8");
      }
    }
    byte[] bytes = content.getBytes(charset);
    return create(contentType, bytes);
  }

这个content是类似于“a=88&b=99”这样的字符串吗?

ringa_leeringa_lee2857 天前617

全部回覆(1)我來回復

  • 迷茫

    迷茫2017-04-17 17:36:56

    推薦你使用 postman ,這個是 chrome 的一款http調試的插件,他可以直接產生okhttp 的程式碼。
    這是我自己調試時用 postman產生的okhttp 的java程式碼。

    回覆
    0
  • 取消回覆