file_get_contents – failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

I was recently wrote Facebook application using graph API , In this case my application need to update settings in developer (


The URL was like this rakan2&page_tab_url=|SF7i4WLEeqLEM2TQrc6wiTGDfET

 If you try the URL in normal browser it can run without  problems but when you run the URL using file_get_contents it would produce 404 errors.

Warning: file_get_contents(xxxx): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/mahadir/fbapps/index.php on line 35

Actually this errors came out because of the parameter in the URL is separated, if you looked carefully at

page_tab_default_name=Personaliti rakan2

you could see that there is a space between it.

So the solution is quite easy, you just need url_encode the parameter itself.


$page_tab_default_name = urlencode("Personaliti rakan2");
$page_tab_url = urlencode("");
$secure_page_tab_url = urlencode("") ;
$privacy_policy_url = urlencode("");

$url = "".$appid."?page_tab_default_name=".$page_tab_default_name."&page_tab_url=".$page_tab_url."&secure_page_tab_url=".$secure_page_tab_url."&privacy_policy_url=".$privacy_policy_url."&website_url=".$page_tab_url."&method=post&".$access_token;

echo file_get_contents($url);


I hope this solution can save out your time on troubleshooting. 🙂







If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

In an effort to prevent automatic filling, you should perform a task displayed below.