search

Home  >  Q&A  >  body text

Content-Type is not added in the post request header of axios

<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粉138711794P粉138711794474 days ago489

reply all(1)I'll reply

  • P粉731977554

    P粉7319775542023-08-15 00:22:39

    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)

    reply
    0
  • Cancelreply