java调用三方接口 get/post请求如何从返回的值中获取响应头?

新手上路,请多包涵

调用e签宝三方接口,用post或者get请求 ,通过三方接口返回的值怎么获取响应头的数据?

阅读 3.5k
3 个回答

向你推荐一个工具包hutool,https://www.hutool.cn/docs

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.8.0</version>
</dependency>

使用

        HttpRequest request = HttpUtil.createGet("https://baidu.com");
        HttpResponse response = request.execute();
        String header = response.header("Content-Type");
        System.out.println(header);

很多http工具包都都可以:

  1. apache http components
  2. okhttp
  3. java11 HttpClient
  4. AsyncHttpClient
  5. Google HttpClient

以前用过e签宝,不咋样。e签宝提供的是sdk,不是给接口信息自己调的,所以楼上两位的都没法直接用,除非自己反编译一下,而且sdk是混淆过的,反编译会很麻烦

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题