2
我有Xamarin应用程序,它具有带数组参数列表的POST请求,并在我的MVC WEB API上使用了代码第一个实体框架。两者都是分开的项目解决方案(.sln)。在MVC Web API上使用Array参数的PostAsync请求
在我的Xamarin项目中,我有PostAsync请求,它提供了数组值列表。
using (var client = new HttpClient())
{
Parameter = string.Format("type={0}¶m={1}",type, param[]);
var data = JsonConvert.SerializeObject(parameters);
var content = new StringContent(data, Encoding.UTF8, "application/json");
using (var response = await client.PostAsync(url, content))
{
using (var responseContent = response.Content)
{
result = await responseContent.ReadAsStringAsync();
}
}
}
然后在我的Web API控制器中,我的客户端也有相同的参数。
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpPost]
[Route("type={type}¶m={param}")]
public BasicResponse applog([FromUri] ProfilingType type , List<string> param)
{
if (ModelState.IsValid == false)
{
throw new ModelValidationException("Model state is invalid.");
}
try
{
if(type == ProfilingType.Login)
{
var command = new SendDataProfilingCommand(param);
CommandHandler.Execute(command);
}
else
{
var command = new UpdateDataProfilingCommand(type,param);
CommandHandler.Execute(command);
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return new BasicResponse
{
Status = true,
Message = Ok().ToString()
};
}
因为我没有使用API,所以我想首先在Postman上或甚至在URL中对它进行测试。但我的问题是,当我尝试使用此URL来测试它下面
http://localhost:59828/api/users/applog?type=1¶m=[1,Caloocan,Metro马尼拉,菲律宾,0,0]
我收到此消息:没有HTTP资源发现,请求URI匹配.... ..
我的问题是,我如何测试我的Web API与列表参数的URL或邮递员?和什么格式我可以使用时发送一个post请求到我的Xamarin PostAsync请求?
[如何将整数数组传递给ASP.NET Web API?](https://stackoverflow.com/questions/9981330/how-to-pass-an-array-of-整数到asp-net-web-api) – Igor
查看重复的链接。您正在为阵列错误地构建您的URL。 – Igor