Here is working example
$response = wp_remote_get( 'https://ww.wp.xz.cn' );
if( is_array($response) ) {
var_dump($response);exit;
}
check documentation here
https://codex.ww.wp.xz.cn/Function_Reference/wp_remote_get
Thread Starter
Rado
(@jeriksson)
can you give a working example using the second example instead as in:
wp_remote_get( 'http://www.example.com/index.php?action=foo', array( 'timeout' => 120, 'httpversion' => '1.1' ) );
but with headers included instead?
My logic makes me think that this would work:
wp_remote_get( 'http://www.example.com/index.php?action=foo', array( 'timeout' => 120, 'headers' => 'http://mydomain.com' ) );
but it doesn’t.
What am i doing wrong?
-
This reply was modified 9 years, 4 months ago by
Rado.
-
This reply was modified 9 years, 4 months ago by
Rado.
I believe the value of the headers argument needs to be a complete header string as one might supply for a call to headers(), like so:
'headers' => 'Referer: http://mydomain.com',
If you have several headers to send, assign an array of string values, each element formatted as in my example. Also note that the Referer: header, as is tradition, is intentionally misspelled. “Referrer” is proper English.
Untested though. If you still have trouble let me know and I’ll dig deeper.
Thread Starter
Rado
(@jeriksson)
thanks, but i can’t get it to work.
wp_remote_get($imageUrl, array('headers' => 'Referer: http://mydomain.com')));
$imageurl is the url to the image.
i’m not quiet sure if it’s the header not being sent of some other issue, the origin of the issue started when a client requested that images that were hosted on his gallery would not to be visited directly, so i added some stuff to an htaccess file where the images reside:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ / [L]
which works perfectly as it should, when someone tries to visit http://mydomain.com/gallery/1.jpg they get a 404 , but if you visit http://mydomain.com and http://mydomain.com/gallery/1.jpg is linked on the page it will find the image as the referer header sent contains the mydomain.com.
The issue is the client is also using a plugin which uses the function wp_remote_get when you publish a new post and it grabs the first image it finds in the post body automatically and attaches it as a thumbnail to the post. This is what am in trying to get to work here, but even if i add the referer header it will not work, it works instantly if i remove the htaccess code.
Any ideas?
-
This reply was modified 9 years, 4 months ago by
Rado.