简体   繁体   中英

Ionic3 with woocommerce rest api having post request?

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

but this does not seems to work.

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.

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.

The CORS specification distinguishes two distinct use cases:

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM