Put request with simple string as request body

前端 未结 8 555
谎友^
谎友^ 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:49

    I was having trouble sending plain text and found that I needed to surround the body's value with double quotes:

    const request = axios.put(url, "\"" + values.guid + "\"", {
        headers: {
            "Accept": "application/json",
            "Content-type": "application/json",
            "Authorization": "Bearer " + sessionStorage.getItem('jwt')
        }
    })
    

    My webapi server method signature is this:

    public IActionResult UpdateModelGuid([FromRoute] string guid, [FromBody] string newGuid)
    
    0 讨论(0)
  • 2020-12-24 14:56

    Have you tried the following:

    axios.post('/save', { firstName: 'Marlon', lastName: 'Bernardes' })
        .then(function(response){
            console.log('saved successfully')
    });
    

    Reference: http://codeheaven.io/how-to-use-axios-as-your-http-client/

    0 讨论(0)
提交回复
热议问题