解决的问题

在这里插入图片描述

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)

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐