美文网首页
关于request

关于request

作者: 水电梁师傅 | 来源:发表于2019-08-02 10:58 被阅读0次

今天弄了弄request,也就是请求,有点像jq

swan.request({
    url: 'https://smartprogram.baidu.com/xxx', // 仅为示例,并非真实的接口地址
    method: 'GET',
    dataType: 'json',
    data: {
        key: 'value'
    },
    header: {
        'content-type': 'application/json' // 默认值
    },
    success: function (res) {
        console.log(res.data);
    },
    fail: function (err) {
        console.log('错误码:' + err.errCode);
        console.log('错误信息:' + err.errMsg);
    }
});

这是官网给的例子,其他都好说,但是post死活拿不到值
$_POST也不行,然后查文档得到几个比较奇怪的写法,比如dataType的值只有json和string,我记得是text还是什么来着
关键是content-type,我依稀记得 好像有application/text application/xml的写法,然后又没有,大概是我记错了
最后的最后,取道post的方法是

 'content-type': 'application/x-www-form-urlencoded' 

改成这样就可以了

相关文章

网友评论

      本文标题:关于request

      本文链接:https://www.haomeiwen.com/subject/mvikdctx.html