当前位置: 首页 > article >正文

从浏览器控制台发送get,post请求

---------------------get请求---------------------------
fetch(url, {
  method: 'get',
})
  .then(response => response.json())
  .then(data => {
    // 获取到响应的数据后的处理逻辑
 console.log(data); 
  })
  .catch(error => {
    // 请求发生错误的处理逻辑
 console.log(error); 
  });


---------------------post请求-------------------------------

fetch(url, {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
  // 如果需要在请求头中添加其他自定义参数,可以在这里添加
  },
 body:JSON.stringify(data) // 请求体中的数据
})
  .then(response => response.json())
  .then(data => {
    // 获取到响应的数据后的处理逻辑
 console.log(data); 
  })
  .catch(error => {
    // 请求发生错误的处理逻辑
 console.log(error); 
  });
 


http://www.kler.cn/a/152987.html

相关文章:

  • 服务器和Linux ,安装R rstudio ,常用软件
  • 基于Java SSM移动电源租赁系统
  • Linux:strace 简介
  • 代码生成器——MyBatis Builder
  • js模块化的好处
  • Task.Run为什么会存在内存泄漏的风险?
  • Docker下安装Redis
  • 【算法每日一练]-图论(保姆级教程篇10 并查集)#POJ1988 #POJ1182
  • Python【走出棋盘】
  • MySQL数据库SQLSTATE[22007]: Invalid datetime format 日期类型不能为空值的解决办法
  • Swagger各版本访问地址
  • Linux命令——watch
  • 模糊C均值(Fuzzy C-means,FCM)聚类的python程序代码的逐行解释,看完你也会写!!
  • sso/单点认证的理解
  • 虹科分享 | 平衡速度和优先级:为多样化的实时需求打造嵌入式网络(4)——从理论到实践:CANopen源代码配置
  • RocketMQ-快速实战
  • 【数电笔记】逻辑代数的基本定律、常用公式
  • 机器学习ROC曲线中的阈值thresholds
  • 传统算法: Pygame 实现快速排序
  • Promise的resolve和reject方法(手写题)