W
W
wertex2016-09-02 23:18:21
Yii
wertex, 2016-09-02 23:18:21

How to make a request through the REST API and get a response?

You need to make a request to a third-party server using the REST API.
I found only information on how to make a REST API server and respond to requests.
the request should look like this:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Token " \
-H "X-Secret: " \
-d '[ "here is the info that send" ]' \
https://ru.ru
In the future, you need to send several hundred such requests, get a response and extract the necessary data from it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wertex, 2016-09-13
@wertex15

Used yiisoft/yii2-httpclient.
The code was something like this:

$client = new Client();
        $response = $client->createRequest()
            ->setFormat(Client::FORMAT_JSON)
            ->setMethod('post')
            ->setUrl('https://ru.ru')
            ->setHeaders(['Content-Type' => 'application/json'])
            ->addHeaders(['Authorization' => ''])
            ->addHeaders(['X-Secret' => ''])
            ->setData(['data' => $data])
            ->send();

R
Rou1997, 2016-09-03
@Rou1997

Use the same curl, it is built into PHP, you need to send a POST request, set 3 headers and content (post body).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question