釘釘小程序post請求參數的格式轉換

解決的問題

在這裏插入圖片描述

1、釘釘小程序的post請求如何發起

httpReq(msg, url, method, data) { // 再次封裝請求
    return new Promise(function(resolve, reject) {
      dd.showLoading({
        content: msg
      });
      dd.httpRequest({
        url: url,
        method: method,
        headers:{"Content-Type":"application/json"},
        data: JSON.stringify(data),
        success: (res) => {
          dd.hideLoading();
          if (res.status == 200) {
            resolve(res);
          } else {
            reject(res);
          }
        },
        fail: () => {
          reject();
        }
      });
    });
  }

調用

this.httpReq('登錄中...','http://localhost:8081/beauty/login','post',{requestAuthCode: "0909"})

或者

this.httpReq('登錄中...','http://localhost:8081/beauty/login','post',{requestAuthCode: res.authCode})

2、請求數據格式定義

headers:{“Content-Type”:“application/json”}
注意放的位置啊,放method下面吧

3、請求數據轉成json

data: JSON.stringify(data)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章