Document

异常全文:java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true) 

异常分析:

  1、发起GET请求,请求的HttpEntity中包含body参数。

    解决方案:改变声明HttpEntity的方式——

        httpEntity = new HttpEntity<>(restUtilParams.getBody(), httpHeaders);
    ==> HttpEntity httpEntity = new HttpEntity<>(httpHeaders);
       ResponseEntity<String> responseEntity =
       templateMap.get(TEMPLATE).exchange(uri, HttpMethod.GET, httpEntity, String.class);

  2、URLConnection发起POST请求少设置参数

    解决方案:为URLConnection 添加两参数——

      URLConnection conn = url.openConnection();
      conn.setDoOutput(true);  
          conn.setDoInput(true);
posted on 2021-08-04 18:24  文白wb  阅读(9160)  评论(0)    收藏  举报