SpringBoot WebClient request with identifier and secret or hashed password
P粉825079798
P粉825079798 2024-02-17 20:33:18
0
1
386

I have a curl php request as shown below

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

What I want to achieve is to perform the same operation in springboot java using web client, below is how I try to do it using web client

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

I'm not getting any reply, my web client may be doing something wrong

P粉825079798
P粉825079798

reply all(1)
P粉510127741

http_build_query Add parameters as query string. In your web client you add them as headers. I think you have to change this:

webClient
.post()
.uri("https://www.myurl.com?action=GetSearchDetails&username=lambistic&password=lambistic#####&responsetype=json")
.retrieve()
.bodyToMono(SearchDetailsResponse.class);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!