I develop an application using the woocommerce v3 API.
I want push an image by remote_url.
But I can’t upload it to Woocommerce by the Product API update
I found in the code the issue the image is downloaded by wp_safe_remote_get from WordPress. But this methode think my URL is not safe.
Why is not safe ?
Can i add some whitlist system to avoid considere this URL like unsafe ?
The WordPress code seems to do a same-host check on urls that are fetched using
wp_safe_remote_get()
.Here’s the source: https://github.com/WordPress/WordPress/blob/c73a812109e1a64ecf21b6a198f949c58d1f2674/wp-includes/http.php
The significant part is the
wp_http_validate_url
function, and in particular lines 524-530, which are here:If
$same_host
isfalse
, the method treats the url as not safe.There’s no whitelist that I can see. You’d probably need to edit the code to use
wp_remote_get()
if you want to avoid the problem.UPDATE: the preceding argument is wrong. The code returns the url even if the host is not the same as long as the port is normal.
If the host of the URL contains one of the following symbols, the URL will be rejected:
:#?[]
Try removing
?sha=989266d5133de145
if without this image can be retrieved.
I’ve been try to upload your image on live server, I use woocommerce v3 API approach, and all is working fine. Maybe you need to re-check your apps function, your server, firewall, increase your timeout http, etc, And the issue may come from image server.
https://github.com/woothemes/woocommerce/blob/master/includes/api/class-wc-api-products.php#L2333
As your issue
wp_safe_remote_get
that you get from, we can tweaking those function in out just to testwp_safe_remote_get
to upload image by url.and here the response header of your image by
wp_safe_remote_get