http请求响应头信息
2015-12-09 10:07
671 查看
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());
}
}
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());
}
}
相关文章推荐
- HttpURLConnnection
- 网络营销包含哪些方面的知识听太原郭文军细讲
- 【高可用HA】Apache (3) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy
- Java读取网络图片
- http 使用curl发起https请求
- 校园网的无线网络建设经验谈
- Python Cookie HTTP获取cookie并处理
- HTTP缓存是如何实现
- Java锁--synchronized(转载zi http://zhh9106.iteye.com/blog/2151791)
- [网络管理]全双工与半双工的区别
- 对TCP/IP网络协议的深入浅出归纳
- Struts2的Action中获取HttpServletRequest对象
- 【计算机网络】:填空题复习等详细解答
- 第二十六天-文件系统选型及nfs网络文件进阶
- Installing .NET Core on Ubuntu-摘自网络
- Android | Android Studio无法使用HttpClient的解决办法
- HttpURLConnection 传参数 避免乱码
- 何为HTTP协议
- 网络编程使用代理方法 , 简化请求和响应
- 厦门巨游网络科技有限公司(HOTPOWER)承接游戏UI外包