Home > Web Front-end > JS Tutorial > body text

How node.js implements network requests through axios

小云云
Release: 2018-03-06 09:13:26
Original
1700 people have browsed it

This article mainly shares with you a node.js method of implementing network requests through axios. It has a good reference value and I hope it will be helpful to everyone.

1. Use Npm to download axios npm install --save axios

var update_url = axios.create({
 baseURL:'debug url'
});
update_url.get('/debug url').then(function (response){
  //response 就是请求url 返回的内容
}
Copy after login

When requesting files using the above method, the default format of the body is not form-data. Therefore, when the data format we need to request is form-data, we need to use the following library request

npm install --save request
Copy after login

2. Request request url, you can use get and post methods.

request.post({url:'http://192.168.1.159/backup/client/interface1s.php?func=getMusicPath',formData:{musicname:task.name}},function optionalCallback(err,httpResponse,body){
  //body为url反馈回来的数据,
}
Copy after login

Related recommendations :
Vue2.0 axios front-end and back-end login interceptor detailed explanation

vue uses axios cross-domain request data instance detailed explanation

Vue2.0 axios front-end and back-end login interceptor

The above is the detailed content of How node.js implements network requests through axios. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template