帶有識別符和秘密或散列密碼的 SpringBoot WebClient 請求
P粉825079798
P粉825079798 2024-02-17 20:33:18
0
1
391

我有一個 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粉825079798
P粉825079798

全部回覆(1)
P粉510127741

http_build_query 新增參數作為查詢字串。 在您的網路用戶端中,您將它們新增為標頭。我想你必須改變這一點:

webClient
.post()
.uri("https://www.myurl.com?action=GetSearchDetails&username=lambistic&password=lambistic#####&responsetype=json")
.retrieve()
.bodyToMono(SearchDetailsResponse.class);
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!