[英]How to send ajax get request to WooCommerce rest API in localhost?
I am using the Woocommerce Rest API. 我正在使用Woocommerce Rest API。 I can send a get request using Postman to the live site that uses
https
but I am currently using xampp for localhost server and I cannot connect to my localhost server. 我可以使用Postman将获取请求发送到使用
https
的实时站点,但是我当前将xampp用于本地主机服务器,并且无法连接到本地主机服务器。
But if I use OAuth 1.0 in Postman and enter my woocommerce key and secret the URL becomes 但是,如果我在Postman中使用OAuth 1.0并输入我的woocommerce密钥并秘密,则URL变为
http://localhost/mywebsite/wp-json/wc/v2/orders/12345?oauth_consumer_key=ck_my_key123&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1531881865&oauth_nonce=CxWcdh&oauth_version=1.0&oauth_signature=fjfjosl12=
The initial form of the URL before the request was http://localhost/mywebsite/wp-json/wc/v2/orders/12345
请求之前URL的初始形式为
http://localhost/mywebsite/wp-json/wc/v2/orders/12345
Now I want to send a jquery ajax getting the request to my localhost server with OAuth 1.0 现在我想发送一个jQuery Ajax,使用OAuth 1.0将请求发送到我的本地主机服务器
j('#getlatestorder').click(function() {
debugger
j.ajax({
type: 'GET',
url: 'http://localhost/mywebsite/wp-json/wc/v2/orders/12345?oauth_consumer_key=ck_my_key123&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1531881865&oauth_nonce=CxWcdh&oauth_version=1.0&oauth_signature=fjfjosl12=',
cache: false,
data: {
format: 'json'
},
success: function(data) {
console.log('Order Received');
console.log(data);
},
error: function(xhr,status,error) {
},
complete: function() {
}
});
});
I am receiving a 401 (Unauthorized)
error for the code above but I can connect in Postman. 我收到以上代码的
401 (Unauthorized)
错误,但可以在Postman中连接。
Do you know if there is anything I can update with my jquery code? 您知道我的jQuery代码是否可以更新任何内容? Any idea is appreciated.
任何想法表示赞赏。 Thanks
谢谢
If you are running woocommerce rest api locally then just add s
to your http
request so i think it will run smoothly. 如果您在本地运行woocommerce rest api,则只需将
s
添加到您的http
请求中,这样我就可以正常运行。
Below is the url it should have for local : 以下是本地应具有的网址:
`https://localhost/mywebsite/wp-json/wc/v2/orders/12345?oauth_consumer_key=ck_my_key123&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1531881865&oauth_nonce=CxWcdh&oauth_version=1.0&oauth_signature=fjfjosl12=`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.