Php 在标头中向guzzle发送apikey的Post请求
我是Guzzle的新手,我正试图向一个网站发出发帖请求。 需要为设置键为Cole ApiKey的自定义标头 进行post请求时,此post请求不需要用户名和密码,只需要标题中的apiKey 我的代码Php 在标头中向guzzle发送apikey的Post请求,php,guzzle,Php,Guzzle,我是Guzzle的新手,我正试图向一个网站发出发帖请求。 需要为设置键为Cole ApiKey的自定义标头 进行post请求时,此post请求不需要用户名和密码,只需要标题中的apiKey 我的代码 $url = "https://infoboost.coleinformation.com"; $body = "Testing Post Request"; $api_key = "API_KEY_HERE"; $client = new Client();
$url = "https://infoboost.coleinformation.com";
$body = "Testing Post Request";
$api_key = "API_KEY_HERE";
$client = new Client();
$client->request('POST', $url, [
'body' => $body,
'headers' => [
"Cole-ApiKey" => $api_key
]
]);
$response = $r->getBody()->getContents();
什么工作不正常?出于某种原因,服务器拒绝了我的请求客户端错误:
POSThttps://infoboost.coleinformation.com
导致不允许使用405方法
这意味着这是服务器端的错误,而不是您的代码。端点不支持POST
请求。这太奇怪了,它会在postman上给出json响应,但当我尝试使用guzzle时,它不会工作得太奇怪。你确定它会发送到同一个端点吗?