我有一個API,它由三個參數(param1,param2,param3)構成。對於電子郵件參數它不起作用,因爲'@'字符。但通常工作正常。請檢查我的下面的代碼。Web API不調用,如果參數包含@字符
API控制器
public class ApiPINVerificationController : ApiController
{
public ApiPINVerificationController()
{
}
[HttpPost]
public IHttpActionResult GetStudentByPIN(string param1,string param2,string param3)
{
//Balance Search Audit Log Entry
SLAF.DataAccessManager.DTO.BalanceSearchLog balanceSearchLog = new DataAccessManager.DTO.BalanceSearchLog
{
PIN=param1,
CellPhone=param2,
Email=param3
};
APIManager.InsertBalanceSearchLog(balanceSearchLog);
return Ok(new
{
Student=objStudent
});
}
}
WebApiConfig
public static class WebApiConfig
{
public static string UrlPrefixRelative { get { return "~/Api"; } }
public static void Register(HttpConfiguration config)
{
//config.Formatters.Add(new BsonMediaTypeFormatter());
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{param}",
defaults: new { param = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "Api2",
routeTemplate: "api/{controller}/{action}/{param1}/{param2}"
);
config.Routes.MapHttpRoute(
name: "Api3",
routeTemplate: "api/{controller}/{action}/{param1}/{param2}/{param3}"
);
}
}
你不能收到這樣的參數,,你可以使用JSON參數或主體內容的參數 –