0

The below cURL works while running shell exec but how do I format this in Guzzle?

shell_exec('curl https://*********************** -H "Authorization: *********************** -X POST -F attributes=\'{"name":"testFile.txt", "parent":{"id":"***********"}}\' -F file=@path/To/File.txt');

I want to convert the shell_exec into Guzzle format like the code below but it produces this error:

Client error: POST https://*********************** resulted in a `405 Method Not Allowed

$response = $client->request('POST', 'https://***********************', [
    'debug' => true,
    'headers' => $headers,
    'form_params' => [
        'attributes' => [
            'name' => 'testFile.txt',
            'parent' => [
                'id' => '***********',
             ]
        ],
     'file' => '@path/To/File.txt',
    ]
]);

Any idea what I need to change?

  • `Error 405` has nothing to do with your code .. It's that the **remote** server isn't allowing the protocol you're trying to perform. – Zak Mar 08 '18 at 17:36

1 Answers1

0

As @Zak already said, 405 is the server's response, it's has nothing to do with your code. You should get the same response with cURL.

BTW, to send files you need multipart, not form_params. And Guzzle doesn't support @... notation as command-line cURL does. So see the docs, there is an example.

Alexey Shokov
  • 4,775
  • 1
  • 21
  • 22
  • Thank you for your responses! I found my solution by converting it to a PHP function. https://stackoverflow.com/questions/41179847/convert-curl-to-be-used-in-php-function – user9331002 Mar 12 '18 at 19:16