我正在尝试使用rest模板创建一个服务来使用来自其他url的List数据,但是当我尝试与其他url进行通信时,它会在调用其他方法之前抛出以下错误。
org.springframework.web.client.HttpClientErrorException: 406 null
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
来电方式:
@RequestMapping(value = "/customer/User/getUserlist", method = RequestMethod.POST,headers="Accept=application/json")
public ResponseEntity<List<User>> getUserList(@RequestBody UserInformation UserInformation)
{
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("UserCode", UserInformation.getUserCode());
map.add("emailID", UserInformation.getCustomerEmailID());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
final HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<MultiValueMap<String, String>>(map ,
headers);
JSONObject jsonObject = null;
try {
RestTemplate restTemplate = new RestTemplate();
if(responseEntity.getBody().equals("true"))
{
ResponseEntity<List<User>> responseEntity1 = restTemplate.exchange(
UserURL+"getUserlist", HttpMethod.POST, entity,
List<User>.class);
List l=responseEntity1.getBody();
return l;
}
else
{
return null;
}
}
catch (Exception e)
{
e.printstacktrace();
}
}
叫方法:
@RequestMapping(value = "/order/getorderlist", method = RequestMethod.POST,headers="Accept=application/x-www-form-urlencoded")
public List<User> getOrderList(@RequestParam String UserCode,
@requestparam String emailID) throws Exception
{
List<User> l=new ArrayList<User>();
// the method will fetch value from db and append it to list
l=orderServiceImpl.getAllOrder(emailID,UserCode);
return l;
}