Found a topic Authorization using CURL but it is not clear. I have an address where I need to log in, I want to authorize through because of the domain. (if you go to the site via a browser, it will automatically recognize you, if you go in locally forgive, enter the login domen \ user). The essence of the problem is that I send a POST request to the specified address, an example, but the server says you are not authorized {"Message": "Authorization has been denied for this request. How can I save the session at the beginning and push the request already?

<?php $curl = curl_init("https://helpdesk.*****.ru:80**/inframanager/sdApi/registerCallEngineer"); // Передача данных осуществляется методом POST curl_setopt($curl, CURLOPT_POST, 1); // Задаем POST-данные $data = 'UserID=b105380a-389c-4c1d-842f-b5ce4c229d5b62197abe66de'; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Выполняем запрос и выводим ответ в браузер curl_exec($curl); // Закрываем CURL соединение curl_close($curl); ?> 

1 answer 1

Use this code:

 $username='ABC'; $password='XYZ'; $URL='<URL>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$URL); curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); $result=curl_exec ($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code curl_close ($ch); 

Source: How to use basic authorization in PHP curl , Suhel Meman