Ionic POST to submit data using a common form submission

GET parameters and use the same splicing splicing

doLogin() {
   let url = "http://loginApiUrl";

  var headers = new Headers()
   headers.append('Content-Type', 'application/x-www-form-urlencoded');

  let options = new RequestOptions({ headers: headers });


  let body =  "username=" +'test' + "&password=" + '[email protected]';

  console.log("Form Data:"+body);

  return this.http.post(url, body, options) .map(res => res.json()).subscribe(
              data => {
                console.log(data);
              },
              err => {
                console.log("ERROR!: ", err);
              }
          );
}

The arguments in the body post request

References
  1. How to send Http Post parameter using x-www-form-urlencoded in Ionic 2
  2. Form data is empty when calling http.post ( ) with ContentType header cyclic object, use a similar key-value pairs into the array, and then using the array join method js

Guess you like

Origin www.cnblogs.com/fsong/p/11258794.html