cURL no response

Hello I am working with a simple API.  I am not sure what I am doing wrong. When I put the URL into the browser and any other restful API tester it seems to work fine..I have the code I am using below, It is just test credentials.  If you put it in the browser it works when I run cUrl it fails..Any help would be appreciated..Thanks!


$ch = curl_init('http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                   
'Content-Type: text/plain; charset=utf-8 ',
'Content-Length: 4198',
'Accept: */*',
'Accept-Encoding: gzip,deflate,sdch',
'Accept-Language: en-US,en;q=0.8,sr;q=0.6,cs;q=0.4'                                                                                
    )                                                                       
);                                                                                                                   
$result = curl_exec($ch);
var_dump($result);
/////////////////////////CONVERT THE RESULTS INTO AN ARRAY//////////////////////////////
$assocArray = json_decode($result, true);

Open in new window

bradley525Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Radek BaranowskiFull-stack Java DeveloperCommented:
what exact result you are getting ?

I ran your code on my local Xampp server and it runs fine, I get full string in response to curl call
0
bradley525Author Commented:
Hmmm mine just keeps thinking and nothing happens...
0
bradley525Author Commented:
The same string as if you but the url in the browser address bar?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Radek BaranowskiFull-stack Java DeveloperCommented:
Didn't understand the above..

I put the code exactly as you pasted it in your first post,

$ch = curl_init('http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                   
'Content-Type: text/plain; charset=utf-8 ',
'Content-Length: 4198',
'Accept: */*',
'Accept-Encoding: gzip,deflate,sdch',
'Accept-Language: en-US,en;q=0.8,sr;q=0.6,cs;q=0.4'                                                                                
    )                                                                       
);        
                                                                                                           
$result = curl_exec($ch);
echo "<br>displaying result:<br>";
var_dump($result);

Open in new window


 and in return I get this:

result ss
0
bradley525Author Commented:
I keep getting the follwing error report from CURL


CURL FAIL: http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json TIMEOUT=5, CURL_ERRNO=7array(22) { ["url"]=> string(203) "http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(5.000333) ["namelookup_time"]=> float(0.00014) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } ["redirect_url"]=> string(0) "" }
0
Radek BaranowskiFull-stack Java DeveloperCommented:
your machine has no route to the server you try to reach:

[7] => 'CURLE_COULDNT_CONNECT',

http://php.net/manual/en/function.curl-errno.php

can you do

ping 66.37.155.94

and

telnet 66.37.155.94 8080

?
0
bradley525Author Commented:
This is the error I get

Curl error: Couldn't resolve host '404.php.net'
0
bradley525Author Commented:
I can not ping 66.37.155.94 either
0
Radek BaranowskiFull-stack Java DeveloperCommented:
sorry, when you are getting this error ?

The url I gave above is a manual reference, not anything you should put in your code.

Can you please run two above commands (ping and telnet) from command line and share the results ?
0
Radek BaranowskiFull-stack Java DeveloperCommented:
so this must be the reason why curl is not working. What machine you are running your php/apache on ?

Is it the same machine on which you can reach the desired url from browser ? If yes, then your browser must have some kind of proxy that routes the request to the server, whereas your php server has it blocked somehow.

If you can't ping and/or telnet the machine you are trying to reach in curl, it is the root cause - no connection to the server.

fix that, and your curl will start working
0
bradley525Author Commented:
When I telnet the command line window is just black
0
Radek BaranowskiFull-stack Java DeveloperCommented:
yes, that means you have no network route to the server you are trying to connect to. work on that first.
0
bradley525Author Commented:
What does that mean? no network route?
0
Radek BaranowskiFull-stack Java DeveloperCommented:
It means you can't connect to this server - network path/route is blocked by firewall or other kind of network problem.
0
bradley525Author Commented:
AH, I tried it on a different server and it still seems to be blocked...
0
Radek BaranowskiFull-stack Java DeveloperCommented:
I'm not aware of your network setup and infrastructure, If you in some kind of company network, you need to work with network admins to open network path to the ip you want. I can't help you much with that :)
0
bradley525Author Commented:
I am in my own office..I am actually just trying to run it from my cell phone and it still fails.
0
bradley525Author Commented:
I am going to get with this company and see what the issue is...I will update you once I resolve it..

Thank you
0
Radek BaranowskiFull-stack Java DeveloperCommented:
ok, wait.

this server does not seem to respond to pings.

can you post me a screen shot of what happens when you do

"telnet 66.37.155.94 8080" ?
0
Ray PaseurCommented:
Please see http://iconoun.com/demo/temp_bradley525.php -- it worked fine for me on my server.

You may not be successfully connected to the internet?

Here is the code I used:
<?php // /demo/temp_bradley525.php
error_reporting(E_ALL);

// SEE: http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28499811.html
$url = 'http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json';

// TRY THE REMOTE WEB SERVICE
$htm = my_curl($url);

// SHOW THE WORK PRODUCT OR BARK OUT ERROR MESSAGES
echo "<pre>";
$obj = json_decode($htm);
print_r($obj);


// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl
( $url
, $timeout=5
, $error_report=TRUE
)
{
    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A CHROME BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE THIS BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );
    curl_setopt( $curl, CURLOPT_VERBOSE,        TRUE   );
    curl_setopt( $curl, CURLOPT_FAILONERROR,    TRUE   );


    // IF USING SSL, THESE MAY BE IMPORTANT
    curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, FALSE  );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE  );
    curl_setopt( $curl, CURLOPT_SSLVERSION,     3      );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE
    if ($htm === FALSE)
    {
        // VISUALIZE ERROR MESSAGES
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return $htm;
}

Open in new window

0
bradley525Author Commented:
This is what I am getting


CURL FAIL: http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json TIMEOUT=5, CURL_ERRNO=28array(22) { ["url"]=> string(203) "http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(5.001577) ["namelookup_time"]=> float(0.001204) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } ["redirect_url"]=> string(0) "" }
0
gr8gonzoConsultantCommented:
Sounds more like a network connection issue.

1. Is your browser configured to use a proxy? If so, have you told cURL to use that same proxy?

2. Are you using any client-side security software (e.g. McAfee HIPS or a firewall of some kind) ?
0
gr8gonzoConsultantCommented:
Sorry, I just saw Radek's comments about the proxy and network - disregard my duplicate comments.
0
bradley525Author Commented:
I have put this code on 3 different servers and I get the same error each time I try to run it



CURL FAIL: http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json TIMEOUT=5, CURL_ERRNO=7array(20) { ["url"]=> string(203) "http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0) ["namelookup_time"]=> float(0.006058) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) }
0
Radek BaranowskiFull-stack Java DeveloperCommented:
are those some standalone servers ? Linux or windows ?

Can you launch browser on either of them (be sure that you run browser on the machine you are having problem on, not your local machine from which you have internet access eg. to this site) and try to put http://66.37.155.94:8080/Lsr/GetReports?clientId=awDemo&accessKey=weatherOrNot&lat=39.3178853&lon=-83.0144546&startTime=2004-08-18&stopTime=2014-08-18&type=Hail&type=Tornado&radius=20&responseFormat=json in address bar and tell us what happens ?
0
bradley525Author Commented:
it is a standalone server and when i click on the URL all of the data shows up that I am trying to pull in via cURL
0
Radek BaranowskiFull-stack Java DeveloperCommented:
and your apache/php server is running on the very same machine you are
"clicking on the URL all of the data shows up that I am trying to pull in via cURL" ??

can you change your code to

$ch = curl_init('http://google.com');

Open in new window


and see what happens ?

what are you running your php server on (I mean, what are you typing in the browser to reach your php file to run?
have you ever been able to use curl from within your php work ? if this is first time, maybe your php server (like Xampp in my case) is blocked by local machine firewall (like windows firewall or symantec endpoint protection) and you can reach external addresses from the browser, but not from other applications (not the ones added to firewall exceptions list).

eg. I'm running local xampp so in chrome I'm typing in:

localhost/testfile.php

frankly, I'm having hard time understanding your setup :(
0
bradley525Author Commented:
I do not receive any error when I use the google url...


I am running this on a VPS. The server is not local, it is running CENTOS and a LAMP stack...
0
gr8gonzoConsultantCommented:
Is your remote server configured with portables? If so, are you logging rejected packets?
0
gr8gonzoConsultantCommented:
Sorry - auto correct screwed up my comment. "iptables" not "portables"
0
Radek BaranowskiFull-stack Java DeveloperCommented:
ok so you are testing the url in your local browser and it works

then you try the code from the remote server it it doesn't, but it works with google.com, am I right ?

if so, then try to run telnet 66.37.155.94 8080 on your remote server and see if it skips to blank screen (that means you got connection, and you can terminate it with Ctrl+]). if not, then you need to work with your VPS provider (is it a kind of virtualization provider or hosting provider ?) to open network path to  66.37.155.94 from there. or, as Gr8gonzo suggest - check iptables there (go to shell and run iptables -L and iptables -L -t NAT ) and post it here.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bradley525Author Commented:
Looks like my servers firewall was blocking it this whole time...You guys have been alot of help. I am not really sure how to award points on this one but I will do my best since it was really an issue on my side.

Thanks!
0
Radek BaranowskiFull-stack Java DeveloperCommented:
Networking for sure
0
Radek BaranowskiFull-stack Java DeveloperCommented:
ok glad you solved it. thx for the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.