爱踢球的小猪 2020-02-29 12:57 采纳率: 0%
浏览 270

httpClient报错Unresolved compilation problem

背景:调用的url外部api网络是可达的,代码我在本机和测试环境都没问题,api应该是没问题的,但是在正式环境会报错如下。httpClient版本是4.1,项目JDK是1.6

报错日志

  Caused by: 
  java.lang.Error: Unresolved compilation problem: 
    at com.baosight.pscs.common.httpClientUtils.doPostJson(httpClientUtils.java:82)

代码部分

public static String doPostJson(String url, String json) throws Exception{
       // 创建Httpclient对象
        HttpClient httpClient = new DefaultHttpClient();
        System.out.println("######################");
           String resultString = "";
           HttpResponse response = null;
           try {
               HttpPost httpPost = new HttpPost(url);
               System.out.println("---------->  setURL:" + url);
               httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
               System.out.println("---------->  Header");

               // 创建请求内容
               //StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
                StringEntity postingString = new StringEntity("{\"account\":\"admin\",\"password\":\"9cbf8a4dcb8e30682b927f352d6559a0\"}");
                System.out.println("---------->  postingString:" + postingString);
                postingString.setContentType("application/json");
                //参数传入

                httpPost.setEntity(postingString);
                System.out.println("---------->  setEntity");
                response = httpClient.execute(httpPost);
                System.out.println("---------->  execute" + httpPost.toString());
                HttpEntity entity = response.getEntity();
                resultString = EntityUtils.toString(response.getEntity(), "utf-8");
                System.out.println(resultString);

           } catch (Exception e) {
               e.printStackTrace();
               throw e;
           } finally {
               httpClient.getConnectionManager().shutdown();
           }
           return resultString;
   }
  • 写回答

1条回答 默认 最新

  • 奋斗的小杨 2023-09-12 20:03
    关注

    看报错是编译问题。仔细检查一下82行,或者用restTemplate

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测