我有一个dotnet核心,它可以在React应用程序中提供此服务:
[HttpPost("[action]")]
public string UpdateUserLangage(string liste)
{
if(liste != null )
{
return liste;
}
else
{
throw new ArgumentNullException();
}
}
我尝试使用axios和访存库调用此服务:
axios
axios.default.post('api/preference/UpdateUserLangage', "test" )
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
获取
fetch('api/preference/UpdateUserLangage', {
method: 'post',
body: JSON.stringify("test")
}).then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
结果,我得到一个错误:
参数liste
始终为null,因此出现错误!
如何解决此问题?
谢谢
答案 0 :(得分:0)
此问题与axios或javascript根本无关。您的请求返回500错误。我的猜测是liste
为空,并且抛出ArgumentNullException
?