nodejs request模块

nodejs request模块

  • 安装
  • 引入
  • 使用
    • request
    • request.post form
    • request.post

安装

npm i request -s

引入

const request = require("request");

使用

request

request({
     
	url: 'http://localhost:3000/record/beginClass',
	method: "POST",
	headers: {
     
    	"content-type": "application/json",
    },
    	body: JSON.stringify({
     description:desc})
    }, function(error, response, body) {
     
        if (!error && response.statusCode == 200) {
     
            console.log(body);
        }
}); 

request.post form

request.post({
     
	url: 'http://localhost:3000/record/beginClass',
	form: {
     
		name: ‘monica’
	},
}, (err, res, body) => {
     
	console.log(body)
})

request.post

request.post({
     
	url: 'http://localhost:3000/record/beginClass',
	body: {
     
		name: ‘monica’
	},
	json: true
}, (err, res, body) => {
     
	console.log(body)
})

你可能感兴趣的:(nodejs request模块)