Put request with simple string as request body

前端 未结 8 722
谎友^
谎友^ 2020-12-24 13:52

When I execute the following code from my browser the server gives me 400 and complains that the request body is missing. Anybody got a clue about how I can pass a simple st

8条回答
  •  余生分开走
    2020-12-24 14:44

    I solved this by overriding the default Content-Type:

    const config = { headers: {'Content-Type': 'application/json'} };
    axios.put(url, content, config).then(response => {
        ...
    });
    

    Based on m experience, the default Conent-Type is application/x-www-form-urlencoded for strings, and application/json for objects (including arrays). Your server probably expects JSON.

提交回复
热议问题