Ionic POST提交使用普通表單提交數據


使用 和 GET 拼接參數一樣拼接

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=" + 'admin@mac.com';

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

這個參數放入 post 請求的 body 中

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 循環對象,使用類似鍵值對的方式放入數組,然后再使用 js的數組 join方法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM