I’m developing a php site using CURL,but it only works on my local server and not on live server.It returns an error ‘could not connect to host’
CURL iS installed on live server and i have tested that.
SSL is installed on live server and I am connecting to port 9301 using curl
ie;http://xx.xxx.xx.xxx:9301/test.
Here is my code:
$request = 'http://xx.xxx.xx.xxx:9301/test';
// The request parameters
$context = 'something';
// urlencode and concatenate the POST arguments
$postargs = 'xmlRequest='.urlencode($context);
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt($ch, CURLOPT_PORT, '9301');
curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
//echo curl_getinfo($session);
echo $err = 'Curl error: ' . curl_error($session);
curl_close($session);
echo $response;
From my testing it’s clear that i can’t connect to a port address via Curl. In order to connect to the port address, need to change any server settings?
That is your problem. The handle isn’t
$chin your case, but$session.Just a typo I guess.
In general: Make sure you display ALL error during development. Log them or put them on screen.
You would have caught this one easily.