I have a curl request, it working fine in my localhost, I have uploaded it to server but it hangs and end with error 500 internal server error. If remove the line echo $output = curl_exec($ch); It works fine.
$url = "https://someserver.com/api/";
$username = "some_user";
$password = "some_apss";
if(!extension_loaded('curl')){
die("Curl extension not loaded");
}
if(!function_exists('curl_init')){
die("curl_init not found");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
echo $output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);`
It's a server side issue. Not this script's fault.
It maybe that the curl extension installed on the server with the script isn't compiled with ssl support.
Execute the folowing code on the server and post back the results:
<?php
$version = curl_version();
$ssl_supported= ($version['features'] & CURL_VERSION_SSL);
echo $ssl_supported == CURL_VERSION_SSL;
it should output 1. if not you have to install the ssl suport for curl
That was the issue with my server port. That port was closed. After opening the port its working perfect. Thank you all
Related
I recently uploaded my project from localhost to a live hosting server. In my project I have used a CURL request, which worked absolutely fine on localhost up til now.
As soon as I moved it on live server (Arizonawebservices.com), that CURL request stopped working. When my page sends the CURL request, it keeps on processing and never returns any output.
I checked server for CURL support (using "which curl" command in PHP's exec() function), and yes it has CURL support enabled.
Also created a test page for manually shooting CURL requests and check if it works ok. Tried www.google.com, www.yahoo.com, and many other URLs, all are working fine, but when I put my original API URL "https://dataviz.sandbox.rcoanalytics.com:10105/oauth/token" in it. It starts behaving like before. I am completely unable to get any response from that CURL request. Any help would be appreciated.
Used following code for testing purpose:
function httpPost($url,$params)
{
$postData = '';
if (!empty($params)) {
//create name value pairs seperated by &
foreach($params as $k => $v)
{
$postData .= $k . '='.$v.'&';
}
$postData = rtrim($postData, '&');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if ($postData != "") {
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
$output=curl_exec($ch);
if($output === false)
{
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
}
curl_close($ch);
return $output;
}
$params = array(
);
echo httpPost("https://dataviz.sandbox.rcoanalytics.com:10105/oauth/token", $params);
The url has an SSL error, so in the cURL request when cURL tries to verify the host it blocks you from accessing the address.
use the following:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
This is obviously insecure method to access the URL but for a host like this one it will do the trick.
So I have been using the below code on my shared hosting server and it has been working fine but now we have moved to a dedicated server but this script is not working?
The dedicated server has CentOS 6.8, Apache 2.2, PHP 7.0.14, MySQL 5.6 and does have curl installed.
I am using a permanent access token also.
$data['access_token'] = '{my permanent access token}';
$post_url = 'https://graph.facebook.com/{my feed ID}/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
$dec = (Array)json_decode($return);
$link = "https://www.facebook.com/".$dec["id"];
I cannot find any errors in the console, is there any way for me to debug this?
Figured it out. I didn't force SSL on the old server but do on the new server so the below line needed to be added after curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
I have been trying to call my website on localhost:1055 and my curl_exec call hangs. When I invoke external URL, it is working fine and I am getting a response. I have tried to turn off my firewalls, I have gone through all articles on stack overflow, but I don't seem to get an answer to this problem. I have seen one post where someone had similar issue but there was no resolution for that. Can anyone help?
I am on OS X Al Capitan version 10.11.6 (15G1004) with PHP 5.6 and I am using internal web server of PHPstorm running on port 1055. This is my code:
<?php
function __singleRequestSending($data, $options = array()) {
// array of curl handles
$ch = curl_init();
// data to be returned
curl_setopt($ch, CURLOPT_URL, $data["url"]);
//curl_setopt($ch, CURLOPT_PORT, 1055);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, urldecode($data["data"]));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}
$data = array(
'url' => "http://localhost:1055/info.php",
'data' => "abc"
);
$res = __singleRequestSending($data);
echo 123;
echo "<pre>";
var_dump($res);
print_r($res);
exit;
?>
I have two servers s1 and s2. I have a file from s1 trying to access a file from s2 through php curl. The curl commands are written using php in s1/test.php and it is requesting s2/file.php.
I tested if curl is present in s1 and it is working fine with all urls except from s2. Also I can access s2 from localhost but not from s1. Please help me.
Here is my curl code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "here the url is placed");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if(!$data)
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
echo $data;
When i execute I am getting: "Curl error: couldn't connect to host"
couldn't connect to host means that sonmething is wrong with the connection between the 2 servers. Check DNS's, ip's firewalls, opened ports and services...
What does running wget in the CLI from s1 to s2 says?
I'm trying to use the PHP Curl library to connect to Experian's API.
When I post a HTTPS request to Experian, I get an HTTP 200 OK response, but nothing more. I am expecting a TTY or ARF response. Do anyone have insight in what I'm doing wrong?
Here's a snippet of my code below for reference
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://stg1.experian.com/lookupServlet1?lookupServiceName=AccessPoint&lookupServiceVersion=1.0&serviceName=NetConnectDemo&serviceVersion=2.0&responseType=text/plain'); //not the actual site
//For Debugging
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,1);
//#2-Net Connect client receives ECALS response. This is the Net Connect URL.
$ecals_url = curl_exec($ch);
//#3-Net Connect client validates that the URL ends with “.experian.com”. If the URL is valid, the processing continues; otherwise, processing ends.
$host_name = parse_url( $ecals_url );
$host_name = explode(".", $host_name['host'] );
$host_name = $host_name[1].'.'.$host_name[2];
if( $host_name == "experian.com" )
{
//#4-Net Connect client connects to Experian using URL returned from ECALS.
echo "step 4 - connect to secure connection<br>";
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch,CURLOPT_URL,$ecals_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch,CURLOPT_CERTINFO,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10s
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec ($ch);
print_r ($result);
It has been a while since I messed with our Experian Net Connect service but I believe you have to base64 encode the username:password value for their system to take it.