Response:{“ Message”:“未找到与请求URI'http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData'相匹配的HTTP资源。”,“ MessageDetail”:“在与请求相匹配的控制器'WooCommerceApi'上未找到任何操作。”}
这是我的代码,用于在api网址中发送订单
function my_api_call( $order_id ){
// Order Setup Via WooCommerce
$order = new WC_Order( $order_id );
// Iterate Through Items
$items = $order->get_items();
$url = "http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData";
$orderid = "OrderId=".$order_id;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $orderid);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
write_log ("Order Id for new user: " .$orderid ." and Response is : ".$response);
}
add_action( 'woocommerce_payment_complete', 'my_api_call');
您的答案就在错误消息中:
Response : {"Message":"No HTTP resource was found that matches the request URI 'http://example.com/Api/WooCommerceApi/SaveSubscriptionAndZoomData'.","MessageDetail":"No action was found on the controller 'WooCommerceApi' that matches the request."}
快速浏览WC文档不会显示任何具有该名称的端点,这是错误消息告诉您的内容。确保您正在呼叫WC中实际存在的端点。