我正在将凭据传递给正在使用的API,但是无法得到响应。这是我尝试过的代码:
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
$request = new HttpRequest();
$request->setUrl('https://api.mindbodyonline.com/public/v6/usertoken/issue');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array(
'Content-Type' => 'application/json',
'SiteId' => '-99',
'Api-Key' => 'apikey12345'
));
$request->setBody('{
"Username": "myusername",
"Password": "mypassword"
}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
?>
</body>
</html>
我看到回声“我的第一个PHP脚本!”在我的页面上,但看不到响应。控制台中没有任何内容。我在做错什么吗?