B
B
black922020-04-02 15:16:59
PHP
black92, 2020-04-02 15:16:59

How to convert curl to PHP?

the goal is to get a token from api.easypay.ua, there is a working code that needs to be redone for php:

curl -X POST \
        --header "Content-Type: 
        application/x-www-form-urlencoded"  \
        --header "Accept: application/json"  \
        --header "PartnerKey: easypay-v2"  \
        --header "locale: UA" \
        --header "AppId: b826a751-0571-47c1-9709-dd639c364919"  \
        --header "PageId: bfe30747-ed11-4143-919b-ed2f91c65114"  \
        -d "client_id=easypay-v2&grant_type=password&username=user&password=pass"  \
  
       "https://api.easypay.ua/api/token"

Here is what I got in php:

$ch = curl_init();
        curl_setopt($ch, 
        CURLOPT_URL, 'https://api.easypay.ua/api/token');
        curl_setopt($ch, 
        CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "client_id=easypay-v2&grant_type=password&username=user&password=pass");
        $headers = array();
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $headers[] = 'Accept: application/json';
        $headers[] = 'Partnerkey: easypay-v2';
        $headers[] = 'Appid: b826a751-0571-47c1-9709-dd639c364919';
        $headers[] = 'Locale: UA';
        $headers[] = 'Pageid: bfe30747-ed11-4143-919b-ed2f91c65114';
        curl_setopt($ch,  CURLOPT_HTTPHEADER, $headers);
        $result = curl_exec($ch);
       if (curl_errno($ch)) {
     echo 'Error:' . curl_error($ch);
        }
         curl_close($ch);

tell me, please, what is wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Lyskov, 2020-04-02
@Vlatqa

Appid, Pageid - your id is lowercase

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question