标签:out 接收 exchange content 方式 epo cat array converter
http://localhost:9093/myTestHttp?name=1 访问 @ResponseBody public TestReponse myTestHttp(TestRequest request){// name为属性值
@Autowired
@Qualifier("restTemplate")
private RestTemplate rest;
访问者 HttpHeaders hh = new HttpHeaders(); hh.setContentType(new MediaType("application","json", Charset.forName("UTF-8"))); hh.setAccept(Arrays.asList(new MediaType("application","json", Charset.forName("UTF-8")))); // hh.setContentType(MediaType.APPLICATION_JSON_UTF8); JSONObject s = new JSONObject(); s.put("name","wsd"); s.put("age","sd"); //String json = "{‘name‘:‘s‘}"; System.out.println("request:"+s.toString()); HttpEntity<String> he = new HttpEntity<String>(s.toString(),hh); ResponseEntity<String> ex = rest.exchange("http://localhost:9093/myTestHttp", HttpMethod.POST,he,String.class); // ResponseEntity<String> ex = rest.postForEntity("http://localhost:9093/myTestHttp",he,String.class); String res = ex.getBody(); System.out.println(" res: "+res); 提供者 public TestReponse myTestHttp(TestRequest request){// name为属性值 结果: 访问者用json方式请求name值无法传递 public TestReponse myTestHttp(String name,String age){ //提供者如此修改,可接收name 必须有 MappingJackson2HttpMessageConverter @@@待解决 public TestReponse myTestHttp(@RequestBody Map<String,String> request){ //提供者如此修改,可接收name
标签:out 接收 exchange content 方式 epo cat array converter
原文地址:https://www.cnblogs.com/xingminghui/p/11967251.html