I have this piece of code:-
$finalData = null;
$url = trim('https://example.portal.com/staging/api/v1/jobs');
$headers = array(
"Accept:*/*",
"xsrf-token:eyJpdiI6IndYd2hkNkJBWGF1OStmRUc4bnllbUE9PSIsInZhbHVlIjoiYk5jdUh1a1lxZTFqK0RPTUxVcnU1UT09IiwibWFjIjoiNGQ5MmVmNjNiOTRjNzkxYjc2MGVkZDRhMWExOTFkOGZmMTE3OWFlZDkxODYyZjk2NDQzOGZhNGZiODcyYWZjNCJ9"
);
$postType = 'CURL_POST_DATA_TYPE_X_WWW_FORM_URLENCODE';
$postData = array(
'auth_token' => '30bb573d6a09d2eee2a564d51742252c',
'version' => 1,
'sort_by' => 'j.title',
'sort' => 'desc'
);
if($postType == 'CURL_POST_DATA_TYPE_X_WWW_FORM_URLENCODE')
{
$dataString = '';
foreach($postData as $keyData => $rowData)
{
$dataString .= rawurlencode($keyData) . '=' . rawurlencode($rowData) . '&';
}
$postData = trim($dataString, "&");
if(empty($headers) || $headers === null)
{
$headers = array("Content-type:application/x-www-form-urlencoded");
}
else
{
$headers[] = "Content-type:application/x-www-form-urlencoded";
}
}
//$headers[] = "Content-type:application/json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, TRUE); // remove body
//curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 260);
curl_setopt($ch, CURLOPT_TIMEOUT, 260);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_errno($ch) . ' ' . curl_error($ch);
}
curl_close($ch);
if($output !== false)
{
$finalData = json_decode($output, true);
}
else
{
echo "False";
}
//echo $httpCode;
print_r($finalData);
When I run the same code from localhost, it connects to the API and gives me the correct data. However, when I upload the script into the server, I get this message:-
Curl error: 56 TCP connection reset by peer
In the server there are several folders. In one folder say example.portal.com I have many curl scripts which is running fine. However, when I put similar script in other folder say example.test.com, I am getting this error.
What could be the issue?