前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >springboot发送http请求,springboot http post json

springboot发送http请求,springboot http post json

原创
作者头像
高久峰
发布2023-07-02 17:35:56
4390
发布2023-07-02 17:35:56
举报

基于springboot?RestTemplate

代码语言:javascript
复制
? ? ? ? // 设置header
? ? ? ? HttpHeaders headers = new HttpHeaders();
? ? ? ? headers.set("Accept", "application/json, text/plain, */*");
? ? ? ? headers.set("Accept-Language", "zh-CN,zh;q=0.9");
? ? ? ? headers.set("Authorization", token);
? ? ? ? headers.set("Connection", "keep-alive");
? ? ? ? headers.set("Content-Type", "application/json");
? ? ? ? headers.set("Origin", apiHost);
? ? ? ? headers.set("Referer", apiHost + "/api/x3-service-bills-center/bills/sapreport/summary/query/report");
? ? ? ? headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");

? ? ? ? // 发送Json
? ? ? ? String json = "{\n" + "? \"sapBillsType\": null,\n" + "? \"billsTypeName\": null,\n" + "? \"sureDate\": [\n" + "? ? \"" + s_date + "T00:00:00.000+0800\",\n" + "? ? \"" + e_date + "T23:59:59.999+0800\"\n" + "? ],\n" + "? \"searchKey\": null,\n" + "? \"setDepotModuleFilter\": null,\n" + "? \"getDepotModuleFilter\": null,\n" + "? \"pageSize\": " + pageSize + ",\n" + "? \"pageIndex\": " + pageIndex + "\n" + "}";

? ? ? ? System.out.println(json);
? ? ? ? HttpEntity<String> request = new HttpEntity<String>(json, headers);

? ? ? ? // 读取数据
? ? ? ? String requestUrl = apiHost + "/api/x3-service-bills-center/bills/sapreport/summary/query/report";
? ? ? ? SapReportSummaryResponse sapReportSummaryResponse = restTemplate.postForObject(requestUrl, request, SapReportSummaryResponse.class);

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com