gpt4 book ai didi

spring-cloud - 如何在运行时更改伪装 URL?

转载 作者:行者123 更新时间:2023-12-04 09:06:10 24 4
gpt4 key购买 nike

@FeignClient(name = "test", url="http://xxxx")
如何在运行时更改伪装 URL (url="http://xxxx")?因为 URL 只能在运行时确定。

最佳答案

您可以添加一个未注释的 URI 参数(可能在运行时确定),这将是用于请求的基本路径。例如。:

@FeignClient(name = "dummy-name", url = "https://this-is-a-placeholder.com")
public interface MyClient {
@PostMapping(path = "/create")
UserDto createUser(URI baseUrl, @RequestBody UserDto userDto);
}

然后用法将是:
@Autowired 
private MyClient myClient;
...
URI determinedBasePathUri = URI.create("https://my-determined-host.com");
myClient.createUser(determinedBasePathUri, userDto);

这将发送一个 POST请求到 https://my-determined-host.com/create ( source )。

关于spring-cloud - 如何在运行时更改伪装 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43733569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com