// 引入 request 组件
const request = require('request')
// 发送 post 请求
request({
url: 'http://localhost:8080/api/user/insert',
method: "POST",
json: true,
headers: {
"content-type": "application/json",
},
body: {
id:'234232332',
name:'张三'
}
},(err,rep,body) => {
if(err){
console.log("request 请求post 出现错误 err : " , err );
return false ;
}
// body表示返回的数据
if(body){
// 请求成功
}
})
// 发送 get 请求
request({
url: 'http://localhost:8080/api/user/getUser',
method: "GET",
json: true,
headers: {
"content-type": "application/json",
},
body: {
id:'234232332'
}
},(err,rep,body) => {
if(err){
console.log(" request 请求get请求出现错误 err:",err)
return false;
}
// body表示返回的数据
if(body){
// 请求成功
}
})
微笑的java
欢迎关注转发评论点赞沟通,让编码不在孤单。
|