I would like to pass the website parameter to webapi, but it does not work.
Webapiconfig:
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
Web api controller: take the parameter and return the htmlsnapshot of another website
[HttpGet] [Route("api/snapshot/{param}")] public string GetSnapShot(string param) { string fragment = param; string content = ""; if (fragment != null) { int firstSlash = fragment.IndexOf("/"); if (firstSlash <= 2) fragment = fragment.Substring(firstSlash + 1, fragment.Length - firstSlash - 1); using (IWebDriver driver = new PhantomJSDriver()) { string url = String.Format("http://domain.com/{0}", fragment); driver.Navigate().GoToUrl(url); content = driver.PageSource; } } return content; }
if I try api / snapshot / du-lieu -> hit the controller normally, but if I go more complicated, for example
api / snapshot /% 2Fdu-lieu% 2Fbong-da-y-Serie-A% 2Fseason% 2F1% 2Ftong-quan → does not work, returns 404
Please inform.
source share