我在执行 POST 请求时收到以下错误:
客户端错误:
POST http://api.hitbox.tv/auth/login
导致400 Bad Request
响应:{"success":true,"error":false,"error_msg":"auth_failed"}
我不确定,是不是因为我的 guzzle 代码有什么问题
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
$client = new Client(["base_uri"=>"http://api.hitbox.tv/"]);
$data = ["login"=>"myId","pass"=>"mypassword","rememberme"=>"",];
try{
$response = $client->request("POST","auth/login",["form-params"=>$data,"content-type"=>"application/x-www-form-urlencoded"]);
}
catch(ClientException $e){
echo $e->getMessage();
}
catch(InvalidArgumentException $e){
echo $e->getMessage();
}
var_dump(json_decode($response,true));
我已经尝试使用 Javascript XMLHttpRequest 使用相同的 api 来发布相同的数据集,并获得了成功的结果。
var xmlhttp;
var data = '{"login":"myId","pass":"myPassword","rememberme":""}';
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status == 200){
return xmlhttp.responseText;
}
xmlhttp.open('POST','https://api.hitbox.tv/auth/login',false);
xmlhttp.send(data);