ww0k
ww0k

Reputation: 33

Symfony equivalent of curl_setopt using the httpClientInterface service

I need to make a call to an external API. The API docs says

curl_setopt($ch, CURLOPT_URL, "https://api.simkl.com/search/file");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
  \"file\": \"Were.The.Fugawis.S01E01E02.WS.DSR.x264-NY2.mkv\",
  \"part\": 1
}");

I'm using Symfony and trying to use correctly the given service HttpClientInterface to make the call with:

// $this->client containing the Symfony\Contracts\HttpClient\HttpClientInterface service 
$response = $this->client->request('POST', 'https://api.simkl.com/search/file', [
    'file' => 'Death_Note-01',
]);

Of course it returns the error

Unsupported option "file" passed to Symfony\Component\HttpClient\NativeHttpClient", did you mean cafile"?

How to properly set the call options using the HttpClientInterface provided by Symfony?

Can't find an answer anywhere in the Symfony docs.

Upvotes: 1

Views: 2134

Answers (1)

Stephan Vierkant
Stephan Vierkant

Reputation: 10144

You can find the documentation here:

$response = $this->client->request('POST', 'https://api.simkl.com/search/file', [
    'extra' => [
        'curl' => [
            CURLOPT_POSTFIELDS => "{
               \"file\": \"Were.The.Fugawis.S01E01E02.WS.DSR.x264-NY2.mkv\",
               \"part\": 1
             }",
        ],
    ],
]);

Upvotes: 1

Related Questions