带有 woocommerce rest api 的 Ionic3 有发布请求吗? [英] Ionic3 with woocommerce rest api having post request?

查看:13
本文介绍了带有 woocommerce rest api 的 Ionic3 有发布请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 woocommerce 和 Ionic 的新手,我正在尝试创建一个使用 woocommerce 作为后端的应用程序woocommerce create order api的post请求如下.

I am new to both woocommerce and Ionic and am trying to create an application with woocommerce as backend I have implemented the get request based rest apis in project but am unable to implement the apis with the post request.the function I tried to write for post request to woocommerce create order api is as follows.

  postOrder(postparams){
        var headers = new Headers();
        headers.append("Accept", 'application/json');
        headers.append('Content-Type', 'application/json' );
        headers.append('consumer_key', 'the key comes here');
        headers.append('consumer_secret', 'the secret comes here');
        let options = new RequestOptions({ headers: headers });
        return this.http.post(this.wc_api_path,postparams,options).map(res => res.json());
  }

但这似乎不起作用.

我已经参考过本教程 本文档 This Doc 但我无法理解问题并实施 api.如果可以用它来解释那就太好了一个例子.

I have already referred to This tutorial This Doc This Doc but am unable to understand the issue and implement the api.it would be great if it could be explained with an example.

推荐答案

这就是 CORS 的工作方式(使用跨域请求时).使用 CORS,远程 Web 应用程序(此处为域为 mydomain.org 的应用程序)选择是否可以通过一组特定的标头来处理请求.

This is the way CORS works (when using cross domain requests). With CORS, the remote Web application (here the one with domain mydomain.org) chooses if the request can be served thanks to a set of specific headers.

CORS 规范区分了两个不同的用例:

The CORS specification distinguishes two distinct use cases:

简单请求.如果我们使用 HTTP GET、HEAD 和 POST 方法,则此用例适用.对于 POST 方法,仅支持具有以下值的内容类型:text/plain、application/x-www-form-urlencoded 和 multipart/form-data.

Simple requests. This use case applies if we use HTTP GET, HEAD and POST methods. In the case of POST methods, only content types with the following values are supported: text/plain, application/x-www-form-urlencoded and multipart/form-data.

预检请求.当简单请求"用例不适用时,会发出第一个请求(使用 HTTP OPTIONS 方法)以检查在交叉环境中可以做什么域请求.发送 OPTIONS 请求的不是 Angular2,而是浏览器本身.这与 Angular 无关.

Preflighted requests. When the ‘simple requests’ use case doesn’t apply, a first request (with the HTTP OPTIONS method) is made to check what can be done in the context of cross-domain requests. It's not Angular2 that sends the OPTIONS request but the browser itself. It's not something related to Angular.

更多详情,你可以看看这篇文章:

For more details, you could have a look at this article:

http://restlet.com/blog/2015/12/15/understanding-and-using-cors/

这篇关于带有 woocommerce rest api 的 Ionic3 有发布请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆