【发布时间】:2019-10-21 21:01:11
【问题描述】:
我正在尝试使用 Guzzle 做一个简单的 API 帖子。然而,API 不断返回错误“UnsupportedApiVersion [Message] => API 版本为‘1’的请求资源不支持 HTTP 方法‘GET’。”
当通过邮递员使用 Content-Type: application/json header 和一个简单的正文进行简单的发布时:
{
"Username" : "xxxxxxx",
"Password" : "xxxxxxx",
"ApplicationID" : "xxxxxxx",
"DeveloperID" : "xxxxxxx"
}
它工作正常,我得到了预期的结果。
但是,当使用以下代码时,我不断收到方法 GET is not supported 错误。
public function connect()
{
$client = new Client([
'base_uri' => $this->url,
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'http_errors' => $this->getHttpErrors(),
]);
return $client;
}
public function login()
{
$client = $this->connect();
$res = $client->post($this->url.'auth/signin', [
'json' => [
'ApplicationID' => xxxxxx,
'DeveloperID' => xxxxxx,
'Username' => xxxxxx,
'Password' => xxxxxx
]
]);
$results = json_decode($res->getBody());
return $results;
}
我没有使用“json”,而是尝试了“form_params”,这给了我相同的结果。
我正在使用 Guzzle 6.3.3
【问题讨论】:
-
很难准确指出可能出了什么问题,但是您是否尝试过将密钥
json替换为query? -
不幸的是使用
query给了我同样的结果