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

此生再无相见时 提交于 2020-03-23 08:01:40

问题


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:

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?

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.


回答1:


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);


来源:https://stackoverflow.com/questions/60553863/put-request-throws-401-no-body-error-and-cannot-be-stored-in-the-response-enti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!