Php 本地主机中的woocommerce rest api产品映像

Php 本地主机中的woocommerce rest api产品映像,php,wordpress,rest,woocommerce,Php,Wordpress,Rest,Woocommerce,我有一个woocommerce网站,我需要在本地主机xampp上使用我的wordpress控制该网站的产品。。。 我可以使用woocommerce的rest api创建产品,但我无法为此产品设置映像。每次我使用rest api发送创建产品请求时,我都会收到以下错误: stdClass对象[代码]=>woocommerce\u产品\u图像\u上载\u错误[消息]=>获取远程图像时出错。错误:未提供有效的URL。。[数据]=>stdClass对象[状态]=>400 我怎样才能解决这个问题 Wordp

我有一个woocommerce网站,我需要在本地主机xampp上使用我的wordpress控制该网站的产品。。。 我可以使用woocommerce的rest api创建产品,但我无法为此产品设置映像。每次我使用rest api发送创建产品请求时,我都会收到以下错误:

stdClass对象[代码]=>woocommerce\u产品\u图像\u上载\u错误[消息]=>获取远程图像时出错。错误:未提供有效的URL。。[数据]=>stdClass对象[状态]=>400


我怎样才能解决这个问题

Wordpress拒绝对其他主机的呼叫。 Localhost与example.com是不同的主机,即使它们位于同一台计算机上

您可以使用http_请求_主机_is_外部筛选器来允许本地主机:

add_filter( 'http_request_host_is_external', 'allow_localhost', 10, 3 );
function allow_localhost( $allow, $host, $url ) {
  if ( $host == 'localhost' ) {
    $allow = true;
  }
  return $allow;
}

您应该在主题的functions.php中添加上述代码。

您是否检查了本地计算机上是否存在此图像?是的,此图像存在于我的本地主机上,我使用wordpress媒体上载了此图像