美文网首页
2019-02-15 Okhttp3问题 Content typ

2019-02-15 Okhttp3问题 Content typ

作者: Albert陈凯 | 来源:发表于2019-02-15 12:22 被阅读6次

    https://blog.csdn.net/Otldan/article/details/73864774

    原文没有做encode,在value里面没有需要encode的时候是不会报错的,但如果有可能会出错

            Request okHttpRequest;
            if (MediaType.APPLICATION_FORM_URLENCODED_VALUE.equalsIgnoreCase(contentType)) {
    
                String requestBodyString = request.keySet().stream()
                        .map(x -> x + "=" + java.net.URLEncoder.encode(request.get(x).toString()))
                        .collect(Collectors.joining("&"));
    
                RequestBody rb = RequestBody.create(mediaType, requestBodyString);
    
                okHttpRequest = new Request.Builder()
                        .url(url)
                        .headers(headers)
                        .method(method, rb)
                        .build();
    
    

    相关文章

      网友评论

          本文标题:2019-02-15 Okhttp3问题 Content typ

          本文链接:https://www.haomeiwen.com/subject/gkypeqtx.html