mujuonly
mujuonly

Reputation: 11861

file_get_contents works but wp_remote_get fails

//$url = 'http://www.mysteryranch.com/Product%20Images/WS17%20Triple%20Bang%20Pouch_10-multicam-hero.jpg';
  $url = 'http://www.mysteryranch.com/Product Images/WS17 Flash Bang Pouch_20-multicam-open.jpg';

              // $url = str_replace( " ", '%20', $url );

                //$response = file_get_contents($url);
                //echo '<pre>';print_r($response);exit;
                $response = wp_remote_get($url );
                echo '<pre>';print_r($response);exit;

Upvotes: 0

Views: 221

Answers (1)

mmm
mmm

Reputation: 1149

It looks like the server filter WordPress client. if you change the user agent, it works :

$response = wp_remote_get($url, [
    "user-agent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0",
]);

Upvotes: 1

Related Questions