【发布时间】:2017-01-17 03:16:07
【问题描述】:
我的请求适用于 ajax,但当我尝试使用 guzzle 重新创建场景时失败。我收到了 400 错误的回复。我有一种感觉,我可能在 guzzle 参数中设置了错误?这是我第一次使用它。
阿贾克斯
var usernameV5 = '108357166';
var passwordV5 = '1234';
var data = {
'type':'base64',
'value':btoa(usernameV5 + ":" + passwordV5),
'namespace':'https://somelink/customers'
};
data = JSON.stringify(data);
$.ajax({
'type':'POST',
'headers':{'Content-Type':'application/json'},
'url':'cantshow.com',
'data':data,
'success':function (result) {
},
'error':function () {
}
});
大吃一惊
$username = '108357166';
$password = '1234';
$client = new \GuzzleHttp\Client();
$result = $client->post('cantshow.com', [
'headers' => [
'Content-Type' => 'application/json'
],
'data' => [
'type' => 'base64',
'value' => base64_encode("'".$username.":".$password."'"),
'namespace' => 'https://somelink/customers'
]
])->getBody();
【问题讨论】:
-
什么版本的 Guzzle?
-
版本 6.2.2 .
标签: jquery ajax laravel guzzle