Content-Type is not added in the post request header of axios
P粉138711794
2023-08-14 11:46:51
<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>
Try this example from the axios documentation https://axios-http.com/docs/multipart