Home  >  Article  >  Web Front-end  >  How node.js implements network requests through axios

How node.js implements network requests through axios

php中世界最好的语言
php中世界最好的语言Original
2018-04-12 11:33:271898browse

This time I will bring you node.jsHow to implement network requests through axios, node.js implements network requests through axiosWhat are the precautions, the following are Let’s take a look at practical cases.

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 返回的内容
}

When requesting a file using the above method, the default format of 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

2. For request URL, you can use get or 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反馈回来的数据,
}

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to php Other related articles on the Chinese website!

Recommended reading:

springmvc cannot accept parameters when axios sends a request

How does vue axios interrupt the request when switching pages? accomplish

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!

Statement:
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