我有一个 curl php 请求,如下所示
$curlInit = curl_init();
curl_setopt($curlInit, CURLOPT_URL, 'https://www.myurl.com/');
curl_setopt($curlInit, CURLOPT_POST, 1);
curl_setopt($curlInit, CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'GetSearchDetails',
'username' => 'lambistic',
'password' => 'lambistic######',
'responsetype' => 'json',
)
)
);
curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curlInit);
curl_close($curlInit);
我想要实现的是在 springboot java 中使用 web client 执行相同的操作,下面是我尝试使用 Web 客户端执行此操作的方式
public Mono<SearchDetailsResponse> sendSearchDetailsRequest() {
return webClient.post()
.uri("https://www.myurl.com/")
.header("Content-Type", "application/json")
.headers(httpHeaders -> {
httpHeaders.set("username", "lambistic");
httpHeaders.set("password", "lambistic######");
})
.retrieve()
.bodyToMono(SearchDetailsResponse.class);
}
我没有得到任何回复,我的网络客户端可能做错了什么
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
http_build_query 添加参数作为查询字符串。 在您的网络客户端中,您将它们添加为标头。我想你必须改变这一点:
webClient .post() .uri("https://www.myurl.com?action=GetSearchDetails&username=lambistic&password=lambistic#####&responsetype=json") .retrieve() .bodyToMono(SearchDetailsResponse.class);