Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put-Request throws 401 [no body] error and cannot be stored in the response entity

I want to change data on a server via a put request, but I always get a 401 [no body] error. The response looks like the following:

enter image description here

I do not really understand why I get this error, because my body is not empty. My code looks like this and the values seem to be okay too. Does anyone have any idea what I'm doing wrong?

enter image description here enter image description here

Postman Update:

The values are different right now (consent and authorisation) since its basically a new request but the values were correct before too so this change should not make a difference.

enter image description here

enter image description here

like image 862
TryHard Avatar asked Dec 11 '25 21:12

TryHard


1 Answers

Looks like you are simply passing invalid authorization header, or maybe not passing it at all.

What happens is that you make a RestTemplate exchange call, then you get 401 from that request, and Spring propagates it and returns 500 - Internal Server Error, because there is no error handling in place.

EDIT: According to your screenshots, you are not replacing your path variables. Update the way you build your URL as listed below.

Map<String, String> pathVars = new HashMap<>(2);
pathVars.put("consent-id", consentId);
pathVars.put("authorisation-id", authorisationId);

UriComponents uri = UriComponentsBuilder.fromUri(mainLink)
    .path("consents/{consent-id}/authorizations/{authorisation-id}")
    .buildAndExpand(pathVars);
like image 92
Alan Sereb Avatar answered Dec 13 '25 10:12

Alan Sereb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!