axios content-type
时间: 2023-08-29 22:13:42 浏览: 152
Axios is a JavaScript library used for making HTTP requests from the browser or Node.js. The content-type header is used to specify the format of the data being sent or received. Axios provides an easy way to set the content-type header for HTTP requests.
To set the content-type header using Axios, you can use the 'headers' property of the configuration object passed to the Axios request method. You can set the content-type header to 'application/json' if you are sending JSON data, or to 'multipart/form-data' if you are sending form data.
Here's an example of setting the content-type header to 'application/json' using Axios:
```javascript
axios.post('/api/data', {
data: { name: 'John', age: 30 }
}, {
headers: {
'Content-Type': 'application/json'
}
})
```
In this example, we are sending a POST request to the '/api/data' endpoint with JSON data. The 'headers' property is used to set the content-type header to 'application/json'.
阅读全文