Heim  >  Fragen und Antworten  >  Hauptteil

SpringBoot WebClient-Anfrage mit Kennung und geheimem oder gehashtem Passwort

Ich habe eine curl phpAnfrage wie unten gezeigt

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

Was ich erreichen möchte, ist, den gleichen Vorgang in Springboot Java mit web client auszuführen. Im Folgenden wird beschrieben, wie ich versuche, dies mit dem Webclient zu tun

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

Ich erhalte keine Antwort, mein Webclient macht wahrscheinlich etwas falsch

P粉825079798P粉825079798219 Tage vor385

Antworte allen(1)Ich werde antworten

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

    Antwort
    0
  • StornierenAntwort