当我从我的离子应用程序调用以下url时,我收到错误:
http://localhost:56776/api/Account/%2B17276669901/RequestResetCode?language=en-US&countryId=9305 404 (Not Found)
这就是我的typrscript文件:
var url= AppSettings.API_URL + 'api/Account/' + encodeURIComponent(phone) + '/RequestResetCode' + lang + '&countryId=' + AppSettings.PREFERRED_COUNTRY;
return this.http.post(url,'');
看起来encodeURIComponent在传递电话号码时无法处理'+'。当我通过没有'+'符号的电话号码时,这是有效的。谢谢你查看这个。仅供参考我有asp.net web api来满足这个要求。我需要在api上配置一些东西吗?
后端:
在控制器级别:[RoutePrefix("api/Account")]
[AllowAnonymous]
[HttpPost]
[HttpOptions]
[Route("{UserLoginName}/RequestResetCode")]
public IHttpActionResult RequestResetCode([FromUri]string userLoginName, [FromUri]string language = null)
{
new Application.Service.RequestResetCode(userLoginName, language);
return Ok();
}
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);