Content-Type is not added in the post request header of axios
P粉138711794
P粉138711794 2023-08-14 11:46:51
0
1
477
<p>I am using axios and trying to send javascript code for post request in the following format</p> <pre class="brush:php;toolbar:false;">let api_post_request = async (resourcePath, params, file, options) => { let headers = { ...(getAccessToken()), 'Content-Type' : 'multipart/form-data' }; try{ await axios({ method: 'post', headers: headers, baseURL: `${Constants.PATH.BASE_URL}`, url: `${resourcePath}`, ...(params ? { params: params } : ""), ...(file ? {data : {file : file}} : "") }); }</pre> <p>The Bearer token is set in the Authorization key, but the Content-Type is not found in the request header in the Network tab. Am I using the correct request format? Due to this issue, I get the <strong>Request failed with status code 415</strong> error. </p>
P粉138711794
P粉138711794

reply all(1)
P粉731977554

Try this example from the axios documentation https://axios-http.com/docs/multipart

import axios from 'axios';

const form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', new Blob(['some content']));

axios.post('https://example.com', form)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template