-1

I have a dotnet core and react application, in which I have this service :

[HttpPost("[action]")]
        public string  UpdateUserLangage(string liste)
        {
            if(liste != null )
            {
                return liste;
            }
            else
            {
                throw new ArgumentNullException();

            }
        }

I tried to call this service using axios and fetch library :

axios

axios.default.post('api/preference/UpdateUserLangage', "test"  )
            .then(function (response) {
                console.log(response);
            })
            .catch(function (error) {
                console.log(error);
            });

fetch

fetch('api/preference/UpdateUserLangage', {
            method: 'post',
                body: JSON.stringify("test")
                }).then(function (response) {
                    console.log(response);
                })
            .catch(function (error) {
                console.log(error);
            });

As a result, I get an error :

error

The parameter liste is always null so I get the error !

How can I fix this issue?

Thanks,

  • Does it work if you include a leading `/`, i.e `'/api/preference/UpdateUserLangage'`? Have you gotten the request to work with an external http client like e.g. Postman? – Tholle Aug 09 '18 at 15:28
  • @Tholle : it is the same result, the issue is the null value of the parameter – Lamloumi Afif Aug 09 '18 at 15:34
  • The question is duplicated: [FromBody string parameter is giving null](https://stackoverflow.com/q/40853188/4752488) – Kevin Hernández Aug 09 '18 at 15:46

1 Answers1

0

The issue is not related to axios or javascript at all. Your request is coming back with a 500 error. My guess would be that liste is null, and it throws ArgumentNullException?

stackoverfloweth
  • 6,669
  • 5
  • 38
  • 69