首页 > 解决方案 > 如何设置 spring.boot 实现的 rest 接口的 put 方法的 Rest 客户端调用?

问题描述

我的控制器:

@Slf4j
@RestController
@RequestMapping("/technology")
@RequiredArgsConstructor
public class MyController {

private final MyService myService;

@PutMapping("/enable/{technology}")
public void useTechnology(@PathVariable String technology, Principal principal) {
    myService.[...]
}

我在 application.yaml 中的用户名/密码:

  security:
    user:
      name: user1
      password: password

我的 RestClient 调用:

PUT http://localhost:8080/technology/enable/tech1
Authorization: Basic dXNlcjE6cGFzc3dvcmQx
Accept: application/json
Cache-Control: no-cache

我总是收到 401 错误:

PUT http://localhost:8080/technology/enable/tech1

HTTP/1.1 401 
Set-Cookie: JSESSIONID=DFE4D6D27992A0183BE7A79B551B1EE7; Path=/; HttpOnly
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
WWW-Authenticate: Basic realm="Realm"
Content-Length: 0
Date: Thu, 08 Aug 2019 07:14:23 GMT

<Response body is empty>

Response code: 401; Time: 17ms; Content length: 0 bytes

我必须设置/更改什么才能使通话正常工作?

标签: javarestspring-bootrest-client

解决方案


推荐阅读