【发布时间】:2021-10-05 09:38:21
【问题描述】:
我正在尝试在 react-native 应用程序中获取我的 asp .net 核心 api。当我用邮递员进行测试时,这个 api 工作正常。但是在 react-native 中我有这个错误。
["https://tools.ietf.org/html/rfc7231#section-6.5.13", "Unsupported Media Type", 415, "00-2608a636e0aeaf4bb2b29a2e1b54370a-2145e9063626d940-00"]
这是我的 API。我已经尝试过 public JsonResult 但没有任何改变。
[HttpPost("register")]
public IActionResult Register([FromBody] TbPersonel model)
{
try
{
// SOME CASES
if (dt.Rows.Count > 0)
{
model.login = true;
return new JsonResult(model.login);
}
else
{
model.login = false;
return new JsonResult(model.login);
}
}
catch (Exception e)
{
Logla.Log(MethodBase.GetCurrentMethod().Name, ControllerContext.ActionDescriptor.ControllerName, e);
return new JsonResult(e);
}
}
反应原生
fetch('http:/.../api/login/register/',{
method:'post',
header:{
'Accept': 'application/json',
// 'Content-type': 'application/json'
'Content-Type': 'application/json; charset=utf-8'
},
body:JSON.stringify({
'kullaniciAdi': userName,
'sifre': userPassword
})
})
.then((response) => response.json())
.then((responseJson)=>{
console.log(Object.values(responseJson));
【问题讨论】:
-
只给
'Content-Type': 'application/json;。并尝试{ "kullaniciAdi": userName, "sifre": userPassword } -
同样的结果,不工作。
-
您可以在浏览器控制台查看网络标签
-
@İbrahimEthemBildirici 你能提供 TbPersonel 的尸体吗
-
公共部分类 TbPersonel { public string KullaniciAdi { get;放; } 公共字符串 Sifre { 获取;放; } 公共字符串 Aciklama { 获取;放; } 公共布尔? Aktif { 得到;放; } 公共布尔?斯林迪{得到;放; } 公共布尔登录 { 获取;放; }..... 更多行 }
标签: c# json react-native api fetch