M
M
makboriska2022-01-10 14:45:36
API
makboriska, 2022-01-10 14:45:36

Why does cURL give a 403 Forbidden error when making a request?

Making a cURL request using php

// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.cryptovoucher.io/merchant/voucher/partner');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n\t\"login\": \"123s\",\n\t\"password\": \"asdasdasdasdasd\",\n\t\"amount\": \"25\",\n\t\"currency\": \"EUR\",\n\t\"orderId\": \"3714cc3a-c25f-47e6-83fc-2da76fe27f340\"\n}");

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);


Gives a 403 Forbidden error

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2022-01-10
@vabka

Forgot to authenticate.
Xs what kind of authorization is expected there, but when you open the page in the browser, a window appears for Basic authentication.

V
Voland69, 2022-01-10
@Voland69

I think the problem is somewhere here: For example, cURL serializes your string a second time or encodes it. Check with the debugger what exactly you are sending in the request.
curl_setopt($ch, CURLOPT_POSTFIELDS, ".....");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question