I was trying to write the same post request via php as i did in python. In python it works well, while in php it does not even reach the server at all. This is php 7.4. Also I can access the server http://someip:2080/api/ via browser. So http://someip:2080/api/ is a public IP, I can even access via browser, so it should work from anywhere.
PHP code:
$payload = array(
'data' => 'data0',
);
// Setup cURL
$ch = curl_init('http://someip:2080/api/');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($payload)
));
$response = curl_exec($ch);
if($response === FALSE){
die(curl_error($ch));
}
and python code:
import requests
import json
headers = {'Content-Type': 'application/json'}
resp = requests.post("http://someip:2080/api/" , data = json.dumps(allparams), headers=headers)
thepara = resp.json()
I have no idea what is wrong I tried around 10 ways to make post request from php and nothing worked.