【发布时间】:2018-03-08 07:22:30
【问题描述】:
当我在命令行上执行此操作时:
curl -X POST -d '{"userDetails":{"username":"myself","password":"Myself123"}}' https://sub.domain.com/energy/api/login
它像预期的那样返回一个 sessionid。
当我在 Laravel 5.5 上使用 Guzzle 6 并执行以下操作时:
$client = new GuzzleHttp\Client();
$login = $client->post('https://sub.domain.com/energy/api/login', [
'userDetails' => [
'username' => 'myself',
'password' => 'Myself123'
]
]);
我收到此错误:
Server error: `POST https://sub.domain.com/energy/api/login` resulted in a `503 Service Unavailable` response: org.json.JSONException: JSONObject["userDetails"] not found.
我做错了什么?
【问题讨论】:
-
在 Guzzle 示例中,您可能没有将其作为 JSON 内容发送。 See here 了解如何操作。