1.fetch的get请求
fetch("http://localhost:8003/comsumer/ctesturl",{
method:"GET",
headers: {
"Content-Type" : "application/json",
"Accept" : "application/json"
},
}).then(function(response)
{console.log(response);
return response.json();
}).then(function(data){
console.log(data)
}).catch(function(err){
console.log("error :",err)
});
优化后
fetch("http://localhost:8003/comsumer/ctesturl",{
method:"GET",
headers: {
"Content-Type" : "application/json",
"Accept" : "application/json"
},
}).then((response) =>
{return response.json().then((data) =>
{console.log(data)}).catch((err) =>{
console.log("error :",err)})
})
2.POST请求
fetch("http://localhost:8003/comsumer/ctesturl",{
method:"POST",
headers: {
"Content-Type" : "application/json",
"Accept" : "application/json"
},
body: JSON.stringify({name: "123",sex: "sss",age: 123}),
}).then((response) =>
{return response.json().then((data) =>
{console.log(data)}).catch((err) =>{
console.log("error :",err)})
})