2019-02-15 Okhttp3问题 Content typ

2019-02-15  本文已影响6人  Albert陈凯

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();

上一篇下一篇

猜你喜欢

热点阅读