0

Used to get content from a url through file_get_contents. Suddenly it stopped working, I get the "Warning: fopen(https://www.cba.am/am/SitePages/ExchangeArchive.aspx): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/xocgzspq/public_html/rates/main/6zuohz.php on line xx" warning.

$url = "https://www.cba.am/am/SitePages/ExchangeArchive.aspx";
$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);  
$html = file_get_contents($url, false, stream_context_create($arrContextOptions));

BTW, getting the same issue with fopen instead of file_get_contents. Haven't changed anything in the code recently, please, help to resolve the issue. Thanks!

LevSahakyan
  • 11
  • 1
  • 5
  • Can't reproduce that but [HTTP 400](https://www.restapitutorial.com/httpstatuscodes.html) is **Bad Request** _The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications._ Maybe that server blocked you out? – vee Sep 30 '22 at 20:08
  • Or try [cURL](https://stackoverflow.com/questions/8482782/file-get-contents-throws-400-bad-request-error-php?rq=1). – vee Sep 30 '22 at 20:10
  • tried curl, got 302 error, added CURLOPT_FOLLOWLOCATION, started to get 400 error. I guess the webpage is denying requests. – LevSahakyan Oct 01 '22 at 19:31
  • any workaround ? :( – LevSahakyan Oct 01 '22 at 19:31
  • If they blocked you out then no way to fix this. I don't know that do they have API for this, if there is then it is better to use their API. – vee Oct 03 '22 at 11:08

1 Answers1

0

I had this same issue before I was facing this issue due to the proxy enabled in cloud flare after disabling it worked out.