【发布时间】:2021-01-13 12:46:32
【问题描述】:
在我的 android 应用程序中实现之前,我正在使用 Postman 进行一些测试。 我在 ASP.NET MVC 中创建了一个 WebAPI,并创建了一个将位置添加到数据库的方法。为此,我得到了一个字符串列表,但总是出现一个错误,指出该方法不存在。我做错了什么?
我的代码:
public class LocalNotificacaoController : ApiController
{
private TransEntities db = new TransEntities();
// POST: api/LocalNotificacao
public bool PostNotificacao(List<string> locais, string emailUser, string tipo_login, string hash)
{
if (!ModelState.IsValid)
{
return false;
}
//will go through each location
foreach (string local in locais)
{
//will check if the location already exists
var PlaceExists = db.Find_Local_Notificacao(local).ToList();
//if the location does not exist, it will add the location to the Notification table
if (PlaceExists.Count == 0)
{
//add place
db.Add_Local_Notificacao(local);
}
//get location id
var res = db.Get_IDLocal_Notificacao(local);
int id = 0;
foreach (var item in res)
{
id = item.Value;
}
//add location and user to the Notification-User table
db.Add_Notificacao_Utilizador(id, emailUser, tipo_login);
db.SaveChanges();
return true;
}
return false;
}
}
}
邮递员
【问题讨论】:
-
不确定查询字符串中的多个
locais能否正常工作。在将方法标记为HttpPost之后(您也可以尝试将您的方法命名为Post),您可能需要将查询字符串更改为locais[0]=str&locais[1]=str1.....
标签: c# asp.net-mvc postman