加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

将curl GET转换为javascript fetch

发布时间:2020-12-13 16:57:16 所属栏目:Linux 来源:网络整理
导读:我可以使用以下命令从解析中成功检索对象: curl -X GET -H "X-Parse-Application-Id:1231231231" -H "X-Parse-REST-API-Key: 131231231" -G --data-urlencode 'where={"uid":"12312312"}' https://api.parse.com/1/classes/birthday` 但我正在努力将其
我可以使用以下命令从解析中成功检索对象:
curl -X GET 
-H "X-Parse-Application-Id:1231231231" 
-H "X-Parse-REST-API-Key: 131231231" 
-G 
--data-urlencode 'where={"uid":"12312312"}' 
https://api.parse.com/1/classes/birthday`

但我正在努力将其转换为javascript,使用下面的代码我会得到状态为200的响应.我假设错误是将data-urlencode转换为数据:

var getObject = function {
    var url = "https://api.parse.com";
    url += '/1/classes/birthday';

    fetch(url,{
        method: 'GET',headers: {
            'Accept': 'application/json','X-Parse-Application-Id': '12122','X-Parse-REST-API-Key': '12121','Content-Type': 'application/json',},data: '{"where":{"uid":"12312312"}}'

    })
    .then(function(request,results) {
        console.log(request)
        console.log(results)
    })
}

谢谢!

解决方法

由于我经常想这样做,我做了 https://kigiri.github.io/fetch/,你可以复制/粘贴一个curl命令,它会给你提取代码.

如果要以不同方式使用它,可以签出源.

edit: The feature was added to chrome devtools 07001

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读