GAE php "urlfetch error" - php

i want to get a webpage content via my gae php application.
but the code doesn't work.
my code is:
echo file_get_contents("http://www.navyfield.com", false);
and i tried my code on php-minishell,http://php-minishell.appspot.com/
it didnt work either.
here is the result
Google App Engine/1.8.7
PHP 5.4.19
>>> file_get_contents("http://www.navyfield.com", false);
file_get_contents(http://www.navyfield.com): failed to open stream: Fetch error
anyone got idea about this?

Done some checking it looks like that site is blocking the connection. I tried with URL fetch and with a raw socket from our IP range.

Related

Unable to communicate with *.roblox.com from PHP Google App Engine

I've done extensive testing, enabled verbose cURL logging (Leaves no logs, gives a generic cURL error #7), tried using the built in handlers through file_get_contents. (Also errored, see below) It seems no matter what if I attempt to request information from anything on the roblox.com domain from my app it gets errored before it can even try. I know it is not the distant end as multiple other sites are working fine aswell as I've used an alternate host to try the same communications that I'm doing with Google App Engine and it worked without any issue. At this point I can only conclude that Google has banned my app from communicating with the ROBLOX website without giving me any indication of any kind. If this is true, why is my app banned, and more importantly, why wasn't I alerted?
cURL output with verbose logging enabled:
https://api.roblox.com/users/get-by-username?username=christbru01
CURL Failed with error #7:
CURL HTTP CODE #0
CURL INFO: 0
This is the code which generated these:
syslog(LOG_DEBUG,(string)$newurl);
syslog(LOG_WARNING,'CURL Failed with error #'.curl_errno($s).": ".curl_error($s));
syslog(LOG_DEBUG,'CURL HTTP CODE #'.curl_getinfo($s,CURLINFO_HTTP_CODE));
syslog(LOG_DEBUG,'CURL INFO: '.curl_getinfo($s,CURLINFO_HTTP_CONNECTCODE));
file_get_contents output:
file_get_contents(https://api.roblox.com/users/get-by-username?username=Christbru01): failed to open stream: Connection error
This is the code which generated this:
echo file_get_contents("link removed due to insufficient reputation");
You need to enable cURL in your instance by adding google_app_engine.enable_curl_lite = "1" to your php.ini file.
https://cloud.google.com/appengine/docs/php/config/php_ini

AtTask API Login Error

I'm trying to access the AtTask API using AtTask StreamClient.php library. I am able to login and extract information using the Chrome Advanced Rest Client, however, I am not able to login to the API from a .php script using StreamClient. The message I keep getting is:
"Logging in...Error: Unknown SSL protocol error in connection to XXXXXXXXXX.attask-ondemand.com:443"
Does anyone have an idea what this means, and how to get around it. My gut feeling is that it has something to do with the configuration of my server.
Thanks in advance.
Problem solved. Very strange, very strange. Apparently, you have to force CURL to use SSL Version 1. I added the line:
curl_setopt($this->handle, CURLOPT_SSLVERSION, 1);
to the CURL initiation part of the script and it started working.

file_get_contents not working on different servers

I am trying to simply use file_get_contents() to get content of http://www.google.com/search?hl=en&tbm=nws&authuser=0&q=Pakistan with same code on 2 different servers. One is getting every thing file while other is getting 403 error. I am unable to know what exactly the reason is. I used phpinfo() on both servers.
One difference I observe is that one use apache2 while other use some other HTTP server named LiteSpeed V6.6. But i don't know how if it affect this file_get_contents() method. For more detail you can see their phpinfo() page link below.
Where file_get_contents getting 403 the phpinfo is; http://zavahost.com/newsreader/phpinfo.php
while where it is working file , here is the phpinfo: http://162.243.5.14/info.php
I will be thankful if someone can tell that what is effecting file_get_contents()? Please let me know if any idea?
403 is an Unauthorized Error. That means you lack sufficient permission to connect to the content at that server. I'm not sure if this could be due to the inability to fetch data from your hosting provider, but it could also be denied based on header information the remote server has flagged as unauthorized.
Try using the answer on this post: php curl: how can i emulate a get request exactly like a web browser? to curl the same data from the server that is getting the 403

PHP file_get_contents sudden failure on server

I was using file_get_contents() to fetch information from an external URL. It was working perfectly on the server before. But now, somehow it fails to work on the server. (No changes in the codes.) It keeps giving me the error: failed to open stream: Connection timed out.
I have tested it on localhost and it works perfectly. I have checked allow_url_fopen option, it is still On.
So, what could be the reason(s)?
file_get_contents does not work well at all with getting remote files and should not be used. It does not deal with slow network connections or redirects, and does not return error codes. You should use curl instead to fetch remote files.
There is an example in the manual for curl_exec:
http://us3.php.net/manual/en/function.curl-exec.php

403 forbidden when trying to call a URL using get variable in php

I am trying to make a request from Java (Android) to send a URL to a php file hosted on a web server.
wv.loadUrl(baseurl + "?url=" + URLEncoder.encode(url,"UTF-8"));
where wv is a web view.
The url generated using the above command is:
http://divu.in/TheRedDevil/readhtml/index.php?url=http://www.manutd.com/en/News-And-Features/Football-News/2013/Oct/jimmy-nicholl-knows-jonny-evans-will-battle-for-place.aspx
I also manually tried to open this link using browser and in both cases I got a 403 forbidden error.
Is it a hosting security issue or I am doing something wrong ?
How can this be solved ?
As others have suggested it is not a problem with Android, it is a problem with your PHP code or host.
It seems like your host somehow disallows loading external files.
If you are using file_get_content to load the external content you might try using curl instead - maybe they don't block that.
<?php
$curl = curl_init('http://www.example.com');
$result = curl_exec($curl);
echo $result;
?>
That URL returns 403 (FORBIDDEN) even with a standard desktop browser. It's got nothing to do with Android. The problem lies with the server/hosting configuration.
From all the research I did in the past hour, I realised that it is the apaches mod_security settings applied by hostgator.com (the providers).
So, for this particular application, I used post to send data from android app to the server and it worked like a charm.
Anyone working on Android app facing such problem may simple use POST request like:
wv.postUrl(baseurl,EncodingUtils.getBytes("url=" + url, "utf-8"));

Categories