I'm trying to query to an OData web service. I tried doing this in Python and it worked fine. But when I tried to do it in PHP, I get the following error:
Curl error: Failed to connect to fse-na-int01.cloud.clicksoftware.com port 443: Connection refused
This is what I tried so far in PHP:
function getTaskStatus($taskKey){
$curl = curl_init();
$url = "https://fse-na-int01.cloud.clicksoftware.com/so/api/objects/Task/?\$select=DisplayStatus&\$filter= Key eq ".$taskKey;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Accept: application/json',
'Content-Type: application/json'
]);
curl_setopt($curl, CURLOPT_USERPWD, "user@domain:password");
$result = curl_exec($curl);
if(curl_errno($curl)){
echo 'Curl error: ' . curl_error($curl);
}
curl_close($curl);
return $result[0]["DisplayStatus"]["@DisplayString"];
}
And this is my Python code (which works fine):
def getTaskStatus(taskKey):
top_level_url = "https://fse-na-int01.cloud.clicksoftware.com/"
usuarioClick = 'user@domain'
passwordClick = 'password'
try:
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, top_level_url, usuarioClick, passwordClick)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
# create "opener" (OpenerDirector instance)
opener = urllib.request.build_opener(handler)
# use the opener to fetch a URL
a_url = "https://fse-na-int01.cloud.clicksoftware.com/so/api/objects/Task/?$select=DisplayStatus&$filter=%20Key%20eq%20"+str(taskKey)
opener.open(a_url)
urllib.request.install_opener(opener)
response = urllib.request.urlopen(a_url)
resultadoJson = json.loads(response.read())
except urllib.error.HTTPError:
return "AuthError"
except urllib.error.URLError:
return "ConnError"
except:
return "UnkownError"
try:
return resultadoJson[0]["DisplayStatus"]["@DisplayString"]
except:
return False
Any ideas why the PHP code isn't working?
Thanks!