zoukankan      html  css  js  c++  java
  • http请求响应头信息

    package aaa;

    import java.io.UnsupportedEncodingException;
    import java.nio.charset.Charset;
    import java.util.Arrays;

    import org.springframework.http.HttpEntity;
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpMethod;
    import org.springframework.http.MediaType;
    import org.springframework.http.ResponseEntity;
    import org.springframework.web.client.RestTemplate;


    public class Test001 {

    public static void main(String[] args) throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("application", "x-www-form-urlencoded"));
    // headers.getAccept().clear();
    // .setAccept(Arrays.asList(new MediaType("application", "json",Charset.forName("GBK"))));
    //headers.setAccept(Arrays.asList(new MediaType("application", "json",Charset.forName("utf-8"))));
    headers.setAccept(Arrays.asList(new MediaType("application", "json",Charset.forName("GBK"))));
    //headers.setAccept(Arrays.asList(new MediaType("application", "json")));

    System.out.println(headers);
    HttpEntity<String> requestEntity = new HttpEntity<String>("auth_token=你好",headers);
    // ResponseEntity<String> exchange = restTemplate.exchange("http://127.0.0.1:8003/open/test_pa/hello/post", HttpMethod.POST, requestEntity, String.class);
    ResponseEntity<String> exchange = restTemplate.exchange("http://10.20.18.55:8008/mhis-fwa-platform/public", HttpMethod.POST, requestEntity, String.class);
    ResponseEntity<byte[]> exchange1 = restTemplate.exchange("http://10.20.18.55:8008/mhis-fwa-platform/public", HttpMethod.POST, requestEntity, byte[].class);
    // ResponseEntity<String> exchange2 = restTemplate("http://10.20.18.55:8008/mhis-fwa-platform/public", HttpMethod.POST, requestEntity, String.class);
    //ResponseEntity<Map> exchange = restTemplate.exchange("http://10.42.8.94:8003/open/mhis-fwa-platform/public", HttpMethod.POST, requestEntity, Map.class);
    //ResponseEntity<String> exchange = restTemplate.exchange("http://10.42.8.94:8003/open/mhis-fwa-platform/public", HttpMethod.POST, requestEntity, String.class);
    System.out.println(new String(exchange1.getBody(),"ISO-8859-1"));
    System.out.println(new String(exchange1.getBody(),"GBK"));
    System.out.println(new String(exchange1.getBody(),"UTF-8"));
    //System.out.println(new String(exchange1.getBody()));

    System.out.println(exchange1.getHeaders());

    }
    }

  • 相关阅读:
    决定迁移过来,深耕于此。。。
    一篇搞定MongoDB
    一篇搞定vue请求和跨域
    自定义全局组件
    一篇搞定vue-router
    一篇搞定Vuex
    vue系列
    .Vue.js大全
    一篇搞定spring Jpa操作数据库
    自定义admin
  • 原文地址:https://www.cnblogs.com/zszitman/p/5031951.html
Copyright © 2011-2022 走看看