【发布时间】:2018-07-08 11:08:40
【问题描述】:
第一次使用 cURL 和 guzzle。这可能是一个简单的问题,但希望有一个“helloworld”示例。
这是我目前拥有的 cURL:
curl --include --request POST \
--header "application/x-www-form-urlencoded" \
--header "X-Access-Token: ACCESS_TOKEN" \
--data-binary "grant_type=client_credentials&client_id=PUBLIC_KEY&client_secret=PRIVATE_KEY" \
'https://api.url.com/token'
这是guzzle代码:
$client = new Client(); //GuzzleHttp\Client
$result = $client->post('https://api.url.com/token', [
'form_params' => [
'sample-form-data' => 'value'
]
]);
我不确定如何使用 guzzle 运行 cURL 命令。生成的 guzzle 代码会是什么样子?
【问题讨论】:
-
这应该已经发送了一个 POST 请求。假设您在 PHP 中启用了
ext_curl,它甚至更喜欢使用 cURL。有什么问题? -
在您传递的选项数组中,您还可以放置
headers键来传递 Auth/Token 标头。见docs.guzzlephp.org/en/stable/request-options.html -
如何使用 guzzle 编写上述 cURL 代码?生成的 php 代码会是什么样子?
-
我不确定如何让问题更清楚。如果不清楚,我道歉。我基本上是在问如何在 php 中运行 cURL。我是 cURL 的新手。