WordPress JSON API AUTH PHP Curl

WordPress JSON API AUTH with PHP Curl

我正在使用 wordpress 并将此插件 https://wordpress.org/plugins/json-api-auth/ 用于 JSON API Auth,我正在尝试 return 使用 curl 取得成功PHP 但每当我 运行 我得到的代码 {"status":"error","error":"Invalid username and\/or password."}

<?php
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username="abcd"&password="abcd"',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
?>

但是当我把它放在浏览器中时 url https://example.com/api/auth/generate_auth_cookie/?username=abcd&password=abcd 我成功了 {"status":"ok","cookie":"xyz","cookie_name":"xyzxyz","user":{"id":1,"username":"abcd","nicename":"abcd","email":"abcd@abcd.com","url":"","registered":"2020-09-10 10:42:41","displayname":"abcd","firstname":"abcd","lastname":"abcd","nickname":"abcd","description":"","capabilities":{"administrator":true},"avatar":null}}

你能帮我看看 PHP 中的 curl 有什么问题吗?

我在代码中使用的CURLOPT_URL的原始版本

CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username="'.$this->input->post('email').'"&password="'.$this->input->post('password').'"',

从 cURL url 查询字符串中删除 "。处理您的请求的 WordPress PHP 会将您的用户名读取为 "abcd" 而不是您尝试的 abcd实现。

CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username="abcd"&password="abcd"'

应该是

CURLOPT_URL => 'https://example.com/api/auth/generate_auth_cookie/?username=abcd&password=abcd'