How to write to php post / get request to the server? The following lines were given in the API instructions as an example:

--- BEGIN --- POST http://example.com/api/Authorization/CreateAuthToken HTTP / 1.1
Content-Length: 38 Content-Type: application / json; charset = utf-8
{"Login": "login", "Password": "password"}
--- END ---

It is not clear what to do with it. (googled .. a bunch of examples, but did not find a complete answer, in php is very weak.)

It is planned in response to receive an authorization code and use it already in a get request for authorization on the server: GET api/integration/v1/inn/​<inn>​/kkts?​AuthToken='код авторизации' Then you can get a request to get the data I need :
GET api/integration/v1/inn/​<inn>​/kkts Answers are assumed in JSON format.

Help please write the server code in php for the task.
Thank.

1 answer 1

You can use CURL for this task, for example

 function get_info_by_curl($URL, $PostFields) { $CH = curl_init(); if ($CH === false) { echo 'Initialization error #'.curl_errno($CH).' ---- '.curl_error($CH); } curl_setopt($CH, CURLOPT_URL, $URL); curl_setopt($CH, CURLOPT_RETURNTRANSFER, true); curl_setopt($CH, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($CH, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($CH, CURLOPT_SSLVERSION, 1); curl_setopt($CH, CURLOPT_TIMEOUT, 30); curl_setopt($CH, CURLOPT_POST, true); curl_setopt($CH, CURLOPT_POSTFIELDS, $PostFields); $Result = curl_exec($CH); $CURL_Error = curl_errno($CH); if ($CURL_Error > 0) { echo 'cURL Error: --'.$CURL_Error.'--<br>'; $RetStr = false; } else { $RetStr = $Result; } curl_close($CH); return $RetStr; } 

When you call the function, you transfer the resource for which the request should be sent, and the parameters (if necessary)

 $URL = 'Ссылка на ресурс'; $PostFields = 'params=1&'; $PostFields .= 'params2=2&'; $PostFields .= 'params3=3; $Response = get_info_by_curl($URL, $PostFields); print_r($Response);