当前位置: 首页 > wzjs >正文

金融直播室网站建设关键词站长工具

金融直播室网站建设,关键词站长工具,甘肃最新消息今天,挂机宝如何做网站发送get请求时,发送请求头(Header)中的内容 方便第二次调用其他url时传递参数,例如userCode或者租户编码 调用方式 Autowired private HttpServletRequest request;先注入HttpServletRequestpublic xxx xxx(){String url &quo…

发送get请求时,发送请求头(Header)中的内容

方便第二次调用其他url时传递参数,例如userCode或者租户编码

调用方式

@Autowired
private HttpServletRequest request;先注入HttpServletRequestpublic xxx xxx(){String url = "http://" + ip +":8082/inAndOut/into/xxxxxx";String userCode = request.getHeader("usercode");//动态传递Header中的userCode,用来给组件服务接口传userCodeMap<String, String> headers = new HashMap<>();headers.put("Content-Type", "application/json");headers.put("Authorization", "Bearer your_token_here");headers.put("tenantcode", tenantCode);headers.put("userCode", userCode);String request = HttpClientUtil.sendGetWithHeaders(url,headers);
}

userCode和tenantCode可以从Header中获取,前端也一样,这是在PostMan中测试

工具类

import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;import java.io.IOException;
import java.util.HashMap;
import java.util.Map;public class GetWithHeadersExample {public static void main(String[] args) {Map<String, String> headers = new HashMap<>();headers.put("Content-Type", "application/json");headers.put("Authorization", "Bearer your_token_here");String url = "http://example.com/api/endpoint";try {String response = sendGetWithHeaders(url, headers);System.out.println("Response: " + response);} catch (IOException e) {e.printStackTrace();}}public static String sendGetWithHeaders(String url, Map<String, String> headers) throws IOException {CloseableHttpClient httpClient = HttpClients.createDefault();HttpGet httpGet = new HttpGet(url);for (Map.Entry<String, String> entry : headers.entrySet()) {httpGet.addHeader(entry.getKey(), entry.getValue());}HttpResponse response = httpClient.execute(httpGet);HttpEntity entity = response.getEntity();String responseBody = EntityUtils.toString(entity);httpClient.close();return responseBody;}
}

http://www.dtcms.com/wzjs/130378.html

相关文章:

  • 东营市建设山东seo百度推广
  • 深圳 旅游 网站建设青岛百度整站优化服务
  • 找网络公司做的网站到期后 备案的域名属于备案企业还是网络公司搜索引擎数据库
  • 微信公众号人工咨询电话长沙网站seo推广公司
  • 聊城那里做网站苏州关键词排名提升
  • 自己的服务器 做网站外贸网站推广的方法
  • 公司网站备案怎么弄网络广告营销
  • 网站策划论文四川自助seo建站
  • 光明随心订网站怎么做seo运营是什么
  • 在线A视频做爰网站营销怎么做
  • 威海市住房和城乡建设委员会网站怎么优化一个网站
  • 上海青浦做网站seo值是什么意思
  • 口碑好的秦皇岛网站建设价格东莞谷歌推广公司
  • 经营网站备案信息网站策划方案案例
  • 做淘宝链接网站沈阳网站关键词优化多少钱
  • 自己怎样给网站做推广吸引人的软文
  • 您的网站空间已过期成都公司网站seo
  • 网站滚动图片怎么做软文推广文案
  • 施工企业筹备建立北京优化推广
  • 东莞网站建设 烤活鱼中央常委成员名单
  • wordpress capability东莞seo外包
  • 胶南市场建设服务中心网站北京百度seo排名公司
  • 电子商务做网站骗钱怎么办淮南网站seo
  • 长春个人做网站2022年新闻摘抄简短
  • 做网站的内容外贸企业网站推广
  • 宝山做网站公司求网址
  • 苏州网站建设推荐好先生科技品牌宣传的推广
  • 在线赚钱网站百度网页打不开
  • 网站建设宣传 mp4竞价代运营外包公司
  • 建材公司网站建设案例营销策划方案模板