Home  >  Q&A  >  body text

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_lee2764 days ago556

reply all(1)I'll reply

  • 迷茫

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

    It is recommended that you use postman, which is an http debugging plug-in for chrome. It can directly generate okhttp code.
    This is the okhttp java code generated by postman when I debugged it myself.

    reply
    0
  • Cancelreply