Ionic3与woocommerce休息api有帖子请求? [英] Ionic3 with woocommerce rest api having post request?

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

问题描述

我是woocommerce和Ionic的新手,我正在尝试创建一个带有woocommerce作为后端的应用程序我已经在项目中实现了基于get请求的rest apis但是我无法使用post request实现apis。我试过的功能写邮件请求到 woocommerce创建订单api 如下。

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());
  }

但这似乎不起作用。

我已经提到本教程 此文档 这个文档但我无法理解这个问题并实现api.it会很棒可以用一个例子来解释。

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方法)来检查在跨域上下文中可以执行的操作要求。
Angular2不是发送OPTIONS请求而是浏览器本身。这与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 /了解和使用cors /

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

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