Wordpress WooCommerce Webhook:无效的URL
我正在设置WooCommerce,以便在创建订单时触发webhook。我已将webhook的URL设置为我们为此目的而设置的本地web API的URL:Wordpress WooCommerce Webhook:无效的URL,wordpress,woocommerce,webhooks,Wordpress,Woocommerce,Webhooks,我正在设置WooCommerce,以便在创建订单时触发webhook。我已将webhook的URL设置为我们为此目的而设置的本地web API的URL: http://localhost:3000/store/orders/new WooCommerce确实使用正确的数据负载触发webhook,但请求在webhook的日志中报告为失败: Status: HTTP http_request_failed Es wurde keine gültige URL übermittelt.: Array
http://localhost:3000/store/orders/new
WooCommerce确实使用正确的数据负载触发webhook,但请求在webhook的日志中报告为失败:
Status: HTTP http_request_failed Es wurde keine gültige URL übermittelt.: Array
从德语翻译过来,意思是“没有传递有效的URL”
随后,我将URL更改为面向web的API()部署,API接收到webhook时没有任何问题
我不确定WC webhook是否不能很好地处理具有自定义端口(在我的例子中是端口3000)的URL,因此我想问一个问题,这是否正确,以及是否有办法使WC webhook在localhost开发环境中很好地发挥作用。这不是自定义端口,而是localhost 在wp includes/http.php wp\u http\u validate\u url()中有一个签入,该签入拒绝所有类型的本地IP,除非在http\u请求上有一个返回true的筛选器特别允许 干杯,
在下面的函数中 /** *验证在HTTP API中安全使用的URL。 * *@自3.5.2起 * *@param string$url *@return false |字符串URL或失败时为false。 */ 评论这行
if ( isset( $parsed_home['host'] ) ) {
//$same_host = ( strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] ) || 'localhost' === strtolower( $parsed_url['host'] ) );
$same_host = false;
} else {
$same_host = false;
}
如果你正在使用另一个端口,比如在laravel中,你必须在这里添加端口
if ( empty( $parsed_url['port'] ) )
return $url;
$port = $parsed_url['port'];
if ( 80 === $port || 443 === $port || 8080 === $port || 8000 === $port )
return $url;
if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port )
return $url;
return false;
}
对于WooCommerce版本3.3.5,Bjorn的解决方案似乎不起作用 在我的例子中,我必须编辑文件
wp-content/plugins/woocommerce/includes/class-wc-webhook.php:185
,方法deliver
注释wp\u safe\u remote\u request
方法,使用不安全的http请求方法
// Webhook away!
$http_call = _wp_http_get_object();
$response = $http_call->request( $this->get_delivery_url(), $http_args );
//$response = wp_safe_remote_request( $this->get_delivery_url(), $http_args );
如果有人仍在寻找答案,我的解决方案是创建一个指向接收WebHook的服务器的DNS记录,然后只允许防火墙上的内部流量 使用DigitalOcean的VPC+防火墙和Cloudflare的步骤:
WooCommerce 4.2.2中的工作方式Wordpress http请求可能会阻止某些端口和主机。 但是,我可以确认再次查询localhost:8080是否可行
另一方面,您也可以修改
http.php
以扩展有效端口的数量在文件末尾插入以下代码后,我解决了这个问题:wp content/themes/MYTHEME/functions.php
function allow_unsafe_urls ( $args ) {
$args['reject_unsafe_urls'] = false;
return $args;
} ;
add_filter( 'http_request_args', 'allow_unsafe_urls' );
令人惊叹的!你让我高兴极了!真的很好,但是港口似乎也有问题。该方法中有一个检查:
如果(80==$port | | 443===$port | | 8080===$port)
,那么它只支持公共端口号。
'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', true, $url ),
if ( 80 === $port || 443 === $port || 8080 === $port || 3000 === $port ) {
function allow_unsafe_urls ( $args ) {
$args['reject_unsafe_urls'] = false;
return $args;
} ;
add_filter( 'http_request_args', 'allow_unsafe_urls' );