2
我拿到的時候我在做一個POST請求以下錯誤:狂飲400錯誤的請求
Client error:
POST http://api.hitbox.tv/auth/login
resulted in a400 Bad Request
response: {"success":true,"error":false,"error_msg":"auth_failed"}
我不知道,是因爲我有什麼毛病我狂飲代碼
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發佈相同的數據集,我在哪裏獲得了成功結果。
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);
真的有用,感謝您的評論, – d3no