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());

    }
    }

  • 相关阅读:
    全站之路一路坑(3)——使用百度站长工具提交站点地图
    全站之路一路坑(2)——在Apache下部署django博客
    全栈一路坑之使用django创建博客
    Django添加模型无法数据迁移解决方法
    一款自动汇报工作的微信机器人
    微信js接口自定义分享内容
    C Primer
    皇家每羊历险记(四)——角色移动
    【转载】Spring Boot 使用SSL-HTTPS
    解决https负载报错:unable to find valid certification path to requested target
  • 原文地址:https://www.cnblogs.com/zszitman/p/5031951.html
Copyright © 2011-2022 走看看