cancel
Showing results for 
Search instead for 
Did you mean: 

curl connection issue

curl connection issue

The following code returns 'Couldn't connect to server' but when I do the equivalent in a form and click submit I get the response 'Hi from Ostendo', is there a setting I am missing?

 

// Get cURL resource
$curl = curl_init();
// Set some options
curl_setopt_array($curl, [
	CURLOPT_RETURNTRANSFER => 1,
	CURLOPT_URL => 'http://<server address>:85/?script=ConnectionTest&test=fred',
	CURLOPT_HTTPHEADER => [
		'Content-Type' => 'application/x-www-form-urlencoded',
		'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'
	]
]);
// Send the request & save response to $resp
$resp = curl_exec($curl);
if ($errno = curl_errno($curl)) {
	$error_msg = curl_error($curl);
	$error_message = curl_strerror($errno);
	echo "<strong>Error detected</strong>, details below<br>{$error_message}<br>";
	$info = curl_getinfo($curl);
	echo 'Took ', $info['total_time'], ' seconds to send a request to ', $info['url'], "<br>";
	echo 'content_type=', $info['content_type'], "<br>";
	echo 'http_code=', $info['http_code'], "<br>";
	unset($info);
}
// Close request to clear up some resources
curl_close($curl);
unset($curl);
echo 'Response = ', $resp;
unset($resp);

Form equivalent here

<form action="http://<server address>:85" method="get">
<input type="hidden" value="ConnectionTest" name="script" />
<input type="submit" value="Submit" />
</form>