httpclient设置请求头

2018-07-24 15:30:54 WARN
DefaultHandlerExceptionResolver:189 - Handler execution resulted in exception: Content type ‘text/plain;charset=ISO-8859-1’ not supported
请求头编码格式的问题

请求时出现请求头有问题,加请求头设置

  post = new HttpPost(url);
            //headers
            if (headers != null && !headers.isEmpty()) {

                headers.put("charset", "utf-8");
                headers.put("Content-Type", "application/json");

                logger.debug("header is " + headers.toString());
                Set<Entry<String, String>> sets = headers.entrySet();
                Iterator<Entry<String, String>> it = sets.iterator();
                while (it.hasNext()) {
                    Entry<String, String> header = it.next();
                    post.setHeader(header.getKey(), header.getValue());
                }
            }

apache HttpClient 4.4.1

 <dependency>
   <groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpclient</artifactId>
     <version>4.4.1</version>
 </dependency>
发布了49 篇原创文章 · 获赞 5 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/wangwenpeng0529/article/details/81187323