nas
nas

Reputation: 2417

How to make curl request by passing raw data to post method?

I have an API. In this API, I pass X-AUTH_TOKEN & X-AUTH-KEY as headers and in the body, I pass raw array data ["1", "2", "3"....]

I have tested it using postman, it is returning me response.

But when I implement it using symfony, I am getting HTTP/2 404 returned for "

This is what I have implemented in Symfony.

$response = $this->httpClient->request('POST', $url, [
            'headers' => [
                'x-auth-token' => $authToken,
                'x-auth-key'   => $authKey
            ],
            'body' => [
                "1",
                "2",
                "3",
                "4",
            ]
        ]);

Can anybody please help me how can I implement?

Thank You.

Upvotes: 1

Views: 406

Answers (1)

nas
nas

Reputation: 2417

Instead of body pass json

$response = $this->httpClient->request('POST', $url, [
            'headers' => [
                'x-auth-token' => $authToken,
                'x-auth-key'   => $authKey
            ],
            'body' => [
                "1",
                "2",
                "3",
                "4",
            ]
        ]);

Upvotes: 2

Related Questions