bradley525
asked on
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);
ASKER
Hmmm mine just keeps thinking and nothing happens...
ASKER
The same string as if you but the url in the browser address bar?
Didn't understand the above..
I put the code exactly as you pasted it in your first post,
and in return I get this:
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);
and in return I get this:
ASKER
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) "" }
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"
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
?
[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
?
ASKER
This is the error I get
Curl error: Couldn't resolve host '404.php.net'
Curl error: Couldn't resolve host '404.php.net'
ASKER
I can not ping 66.37.155.94 either
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 ?
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 ?
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
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
ASKER
When I telnet the command line window is just black
yes, that means you have no network route to the server you are trying to connect to. work on that first.
ASKER
What does that mean? no network route?
It means you can't connect to this server - network path/route is blocked by firewall or other kind of network problem.
ASKER
AH, I tried it on a different server and it still seems to be blocked...
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 :)
ASKER
I am in my own office..I am actually just trying to run it from my cell phone and it still fails.
ASKER
I am going to get with this company and see what the issue is...I will update you once I resolve it..
Thank you
Thank you
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" ?
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" ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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) "" }
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"
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) ?
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) ?
Sorry, I just saw Radek's comments about the proxy and network - disregard my duplicate comments.
ASKER
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) }
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"
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 ?
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 ?
ASKER
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
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
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 :(
"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');
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 :(
ASKER
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...
I am running this on a VPS. The server is not local, it is running CENTOS and a LAMP stack...
Is your remote server configured with portables? If so, are you logging rejected packets?
Sorry - auto correct screwed up my comment. "iptables" not "portables"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ok glad you solved it. thx for the points.
I ran your code on my local Xampp server and it runs fine, I get full string in response to curl call