han73748196
2021-01-22 20:21
采纳率: 95.5%
浏览 191
已结题

HttpClient发送Put请求

http://127.0.0.1:8080/x x x/xx?id=xx&value=xxx

 

类似这样的接口请求为PUT。如何进行发送请求获取返回值

  • 收藏

2条回答 默认 最新

  • 阳沉 2021-01-22 22:14
                //设置uri
              String url = "https://pacaio.match.qq.com/irs/rcd?cid=146&token=49cbb2154853ef1a74ff4e53723372ce&ext=ent&page="+page+"&callback=__jp11";
    
              //获取HttpClient对象
              CloseableHttpClient client = HttpClients.createDefault();
    
              //获取get对象
              HttpGet get = new HttpGet(url);
    
    
              //设置请求头内容
              // get.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36");
    
              //发送请求
              CloseableHttpResponse response = client.execute(get);
    
              //判断请求结果
              if (response.getStatusLine().getStatusCode() == 200) {
                  //获取响应体
                  HttpEntity entity = response.getEntity();
    
                  //读取响应体内容
                  String string = EntityUtils.toString(entity, "gb2312");
                //解析响应体
                    
              }
                URL url1 = new URL(buffer.toString());
                URLConnection connection = url1.openConnection();
                InputStream inputStream = connection.getInputStream();
                String result = IOUtils.toString(inputStream);
                JSONObject jsonObject = JSONObject.parseObject(result);
                  //解析Json
    1 打赏 评论
  • foralllove 2021-01-23 16:13

    引入 hutool jar

    打赏 评论

相关推荐 更多相似问题