My task is writting a code to fetch data from rest API via URL like this
curl -k -v -XPOST -H "username: password" -H "Content-type: application/json" http://localhost:8181/api/rest/person/query -d '
{
"name": "person's name",
"role": "role code",
"programme": "programme code"
}'
And here's my code
public JsonUser fetchJsonUserByName(String name) throws IOException{
String jsonName = "'{'name': "+"'"+name+"'}'";
String url = "/person/query -d "+jsonName;
ResponseEntity<JsonUser> response = restTemplate.getForEntity(url, JsonUser.class);
try {
if(response.hasBody()) return response.getBody();
else return null;
} catch (HttpStatusCodeException e) {
if(e.getStatusCode() == HttpStatus.NOT_FOUND) return null;
throw new IOException("error fetching user", e);
} catch (Exception e) {
throw new IOException("error fetching user", e);
}
}
And I got the error code 500 when I run my code, where was I wrong?