How to send a POST request of the following form:
POST /gate/ki-site-api/ HTTP/1.1 Host: api.site.ru Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded id=get_pdf&username=username¶ms=... I try to do this:
<? ini_set('display_errors',1); error_reporting(E_ALL); $url = 'https://api.site.ru/gate/sie-api/'; $data = array('id' => 'make_pdf', 'username' => 'username','account_id' =>'1152289', 'period_id' => '201705'); $params = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($params); $result = file_get_contents($url, true, $context); if ($result === FALSE) var_dump($result); ?> I get the answer:
HTML> string (51) "{" err_msg ":" Authorization failed. "," Err_code ": 1}"
From the documentation:
In order to access a specific API method, you need to send a request using the POST method to the ROOT URL. This request must contain the following required parameters: id - the identifier of the method that you intend to call. For example, get_main_id. See the section of the relevant method group. username - your username - username.
I can not understand how to get authorized and get the necessary data. $ url and username in the description are changed. Can I not pass authorization due to the fact that I am performing a request from a third-party site?