2019-02-15 Okhttp3问题 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

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 type 'application/x-www-form-urlencoded;charset=UTF-8' not supported)