So I have used our web server to send PHP cURL post/patch requests to our partner servers. For some reason it suddenly stopped working and our partners are saying that everything is the same on their side (not sure about that). When I'm sending with Postman then everything works fine.My cURL code (It's getting either HTTP error 200 or nothing):
<?php$username = 'user';$password = 'pw';$api_url = "url_to_rest_api";$data = array('requests' => array( 0 => array('request_id' => '1' ) , ) , );$curl = curl_init();curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");curl_setopt($curl, CURLOPT_URL, $api_url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);curl_setopt($curl, CURLOPT_POST, true);curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));$response = curl_exec($curl);if(curl_errno($curl)){ echo 'Curl error: ' . curl_error($curl);}curl_close($curl);echo $response;?>
Postmand cURL export code (that works):
curl --location 'url_to_rest_api' \--header 'Content-Type: application/json' \--header 'Authorization: Basic' \--data '{"requests": [ {"request_id": "1" } ]}'
I also tried to use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE) and curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false) but it is not working.