所以我一直在尝试向期待的Wordpress API发出请求 http标头中的用户名和密码。
我在Postman尝试了这个,它完美无缺。
cURL代码:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost/wptesting/wp-content/plugins/multisite-json-api/endpoints/create-site.php",
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n \"title\" : \"test\",\n \"email\" : \"test@email.com\",\n \"site_name\" : \"test\"\n}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
"password: dummypassword",
"user: dummyuser"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
然而......当我和Guzzle尝试同样的事情时,我得到了这样的回应: {“id”:“access_denied”,“message”:“无效的用户名或密码”,“网址”:...}
代码:
<?php
require_once 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
$client = new Client();
$res = $client->request('POST', 'http://localhost/wptesting/wp-content/plugins/multisite-json-api/endpoints/create-site.php',
['json' =>
['email' => 'test@email.com',
'site_name' => 'test',
'title' => 'test'
]
],['headers' =>
["password" => "dummypassword",
"user" => "dummyuser"
]
]);
?>
我不知道我做错了什么......