httppost

   private List<ExtConfigQueryResult> httpPost(List<Query> requests) {
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<Result> resultList = null;
        try {
            URI uri = URI.create("http://www.baidu.com");
            HttpPost httpPost = new HttpPost(uri);
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();

            StringEntity entity = new StringEntity(JsonUtil.object2Json(requests), Charsets.UTF_8);
            entity.setContentType("application/json");

            httpPost.setEntity(entity);

            CloseableHttpResponse response = httpClient.execute(httpPost);
            String res = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
            resultList = JsonUtil.json2List(res, Result.class);
            return resultList;
        } catch (Exception e) {
            logger.error("http 请求异常", e);
            throw e;
        } finally {
            logger.info("http 请求单接口 结束 request ={},response ={} spend = {}ms", requests, resultList, stopwatch.elapsed(TimeUnit.MILLISECONDS));
        }

    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用内容,idea http post是指使用IDEA开发工具进行HTTP POST请求的操作。具体步骤如下: 1. 打开IDEA开发工具,并创建一个新的Java项目。 2. 导入所需的HTTP客户端库,例如Apache HttpClient或OkHttp。 3. 创建一个HTTP POST请求对象,并设置请求的URL、请求头、请求体等参数。 4. 发送HTTP POST请求,并获取服务器的响应。 5. 解析并处理服务器的响应数据。 以下是一个使用Apache HttpClient库进行HTTP POST请求的示例代码: ```java import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import java.io.IOException; public class HttpPostExample { public static void main(String[] args) { // 创建HttpClient对象 HttpClient httpClient = HttpClientBuilder.create().build(); // 创建HttpPost对象,并设置请求URL HttpPost httpPost = new HttpPost("http://example.com/api/endpoint"); try { // 设置请求头 httpPost.setHeader("Content-Type", "application/json"); // 设置请求体 String requestBody = "{\"key1\":\"value1\", \"key2\":\"value2\"}"; StringEntity entity = new StringEntity(requestBody); httpPost.setEntity(entity); // 发送HTTP POST请求 HttpResponse response = httpClient.execute(httpPost); // 获取服务器的响应 HttpEntity responseEntity = response.getEntity(); String responseBody = EntityUtils.toString(responseEntity); System.out.println("Response: " + responseBody); // 处理响应数据 // ... } catch (IOException e) { e.printStackTrace(); } } } ``` 请注意,这只是一个示例代码,实际使用时需要根据具体的需求进行修改和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值