欢迎光临
我们一直在努力

发送POST请求

var data = {"code":0,"msg":"你好"};
fetch("http://localhost:55087/Forguncy/ServerCommand/data", {
  method: 'POST',
  body: JSON.stringify(data)
})
.then(response => response.json())
.then(response => {
    console.log(response)
})
.catch(err => console.error(err));

//响应头有跨域头,就可以实现跨域

//GET访问
fetch('http://localhost:55087/Forguncy/ServerCommand/data')
.then(response => {
if (response.ok) {
return response.text();
}
throw new Error('Network response was not ok.');
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error('There was a problem with your fetch operation:', error);
});

 

赞(0) 打赏
未经允许不得转载:豪~豪的个人中心 » 发送POST请求

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏