账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    fetch get方法和post方法的使用区别
    33
    0

    今天学习fetch,在学习get和post方式时,在实验过程中,发现get能成功获取到api中的数据,而post不知道哪里写错了。get方法如下没问题

    fetch('https://search.heweather.com/find?location=北京&key=bc08513d63c749aab3761f77d74fe820',{
          method:'GET'
        }) // 返回一个Promise对象
        .then((res)=>{
          return res.json();
        })
        .then((res)=>{
          console.log(res) // res是最终的结果
        })

    而post方法不知道哪里写错了 ,请指点

    const content = {location:'北京',key:'bc08513d63c749aab3761f77d74fe820'} 
    fetch('https://search.heweather.com/find',{
          method:'POST',
          body:JSON.stringify(content)
        }) // 返回一个Promise对象
        .then((res)=>{
          return res.json();
        })
        .then((res)=>{
          console.log(res) // res是最终的结果
        })
        //报错 invalid key

    还是这个API只能用GET方式调用?初学API的知识,请知道的朋友能详细解答下,谢谢啦

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部