request模块发送restful请求

const request = require('request')

request.get({
    url:'http://localhost:8080'
},(err,response,body)=>{
    if(err){
        console.log(err)
    }
    if(body){
        console.log(body)
    }    
})

request.post({
    url:'http://localhost:8080',
    body:'name=papi&age=1212'
},(err,response,body)=>{
    if(err){
        console.log(err)
    }
    if(body){
        console.log(body)
    }  
})

request.put({
    url:'http://localhost:8080',
    body:'name=papi&age=1212'
},(err,response,body)=>{
    if(err){
        console.log(err)
    }
    if(body){
        console.log(body)
    }  
})

request.delete({
    url:'http://localhost:8080',
    body:'name=papi&age=1212'
},(err,response,body)=>{
    if(err){
        console.log(err)
    }
    if(body){
        console.log(body)
    }  
})

request.patch({
    url:'http://localhost:8080',
    body:'name=papi&age=1212'
},(err,response,body)=>{
    if(err){
        c

你可能感兴趣的:(node.js)