【发布时间】:2020-07-14 11:54:27
【问题描述】:
我有一个简单的注册表单,用户可以在我的应用中注册,现在我想将提交的数据发送到另一个服务。
首先,我使用邮递员面板中的原始选项测试我的请求,如下所示。
API 网址:app3.salesmanago.pl/api/contact/upsert
JSON DATA:
{
"clientId":"w2ncrw06k7ny45umsssc",
"apiKey":"ssssj2q8qp4fbp9qf2b8p49fz",
"requestTime":1327056031488,
"sha":"ba0ddddddb543dcaf5ca82b09e33264fedb509cfb4806c",
"async" : true,
"owner" : "adam@rce.com",
"contact" : {
"email" : "test-1@konri.com",
"name" : "Test",
"address":{
"streetAddress":"Brzyczynska 123",
}
}
}
我得到以下成功结果
{
"success": true,
"message": [],
"contactId": "b52910be-9d22-4830-82d5-c9dc788888ba",
"externalId": null
}
现在在 laravel 中使用 guuzle htpp 请求
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$current_timestamp = Carbon::now()->timestamp;
$client = new Client();
$request = $client->post('app3.salesmanago.pl/api/contact/upsert', [
\GuzzleHttp\RequestOptions::JSON => [
'headers' => [
'Accept' => 'application/json, application/json',
'Content-Type' => 'application/json',
'clientId' => 'dd2ncrw06k7ny45umce',
'apiKey' => 'ddjdd2q8qp4fbp9qf2b8p49fdzd',
'sha' => ' wba0b543dcaf5ca82b09e33264fedb4509cfb4806ec',
"requestTime" => $current_timestamp,
"owner" => "testemail@wp.com",
],
'form_params' => [
'name' => $data['name'],
'email' => $data['email'],
]
]
]);
$response = $request->getBody();
$r = json_decode($response);
dd($r);
return $user;
}
当我运行我的应用程序并发送表单数据时,我会使用与邮递员相同的数据来获取此信息
{#306 ▼
+"success": false
+"message": array:1 [▼
0 => "Not authenticated"
]
+"contactId": null
+"externalId": null
}
谁能告诉我为什么在 Postman 中一切正常,但在 laravel 中却失败了?
我的代码有什么问题?
【问题讨论】:
标签: php json laravel guzzle guzzle6