小编raj*_*don的帖子

Guzzle Post请求与auth

我第一次使用guzzle.任何人都可以告诉我如何为此请求编写Guzzle电话.

curl -X POST -u username:password -H "Content-Type: application/json" https://xyz/api/v1/accounts.json -d '{"user":{"username":"test","password":"xyz","first_name":"test","last_name":"test","email":"test@test.com","roles":["Administrator"]}}'
Run Code Online (Sandbox Code Playgroud)

我在卷曲请求的-u中遇到问题.

I have written this code.
$response = $client->post($url, [
    'headers' => ['Content-type' => 'application/json'],
    'auth' => ['username:password'],
    'json' => [
        'username' => 'test'
    ],
]);
$results = $response->json();
Run Code Online (Sandbox Code Playgroud)

我试过这个但无法调用API

任何建议或帮助.

php json curl guzzle

2
推荐指数
1
解决办法
3484
查看次数

标签 统计

curl ×1

guzzle ×1

json ×1

php ×1