我试图通过传递一个对象并获得响应来调用rest端点。它在邮递员工作。这是我的网址:https://test.ap.com/rest/user/create
body:{“gender”:“MALE”,“weight”:965.0,“height”:40.0,“name”:“testuser”}
,回复是
{“id”:“1234”,“令牌”:“1234%”}
这是我的代码:
@RequestMapping(value = "/createUser", method = { RequestMethod.POST})
public createUserInfo() throws Exception
{
UserData userData = new UserData();
userData.setGender("MALE");
userData.setWeight(965.0);
userData.setHeight(40.0);
userData.setName("test1");
String url="https://test.ap.com/rest/user/create";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Object> entity = new HttpEntity<Object>(userData, headers);
ResponseEntity<Object[]> response= restTemplate.postForEntity(url, entity, Object[].class);
}
我收到以下错误:
org.springframework.web.client.HttpServerErrorException: 500 null
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:66)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:407)
at
我尝试更改标题并为响应类型创建了一个对象,但对我来说没有任何作用。我应该添加什么来解决这个问题?
答案 0 :(得分:0)
我认为
private static long getCompressSize(byte[] input)
{
long length = 0;
using (MemoryStream compressedStream = new MemoryStream())
{
compressedStream.Position = 0;
using (DeflateStream compressionStream = new DeflateStream(compressedStream, CompressionLevel.Optimal, true))
{
compressionStream.Write(input, 0, input.Length);
}
length = compressedStream.Length;
}
Logger.WriteLine("input length:" + input.Length + " compressed stream: " + length);
return length;
}
应该是
String url="https://test.ap.com/rest/user/create";
出于某种原因,最后一次斜线非常重要