首页  >  问答  >  正文

带有标识符和秘密或散列密码的 SpringBoot WebClient 请求

我有一个 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);
}

我没有得到任何回复,我的网络客户端可能做错了什么

P粉825079798P粉825079798219 天前387

全部回复(1)我来回复

  • P粉510127741

    P粉5101277412024-02-18 15:02:36

    http_build_query 添加参数作为查询字符串。 在您的网络客户端中,您将它们添加为标头。我想你必须改变这一点:

    webClient
    .post()
    .uri("https://www.myurl.com?action=GetSearchDetails&username=lambistic&password=lambistic#####&responsetype=json")
    .retrieve()
    .bodyToMono(SearchDetailsResponse.class);

    回复
    0
  • 取消回复