0

i need to invoke web api2 from angular4 my url looks like below my url looks like api/schedule/getdata/date/2018-04-18/utilityid/utilityname/poolid/pool/name where poolid contains special characters for example: "pool/name". how can i pass this special character (/) from angular4 to WebAPI2.

I tried with FromUri at WebAPI level- but still failure

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable

  • You'll most likely have to escape those characters. `/` for example is escaped with `%2F` – Brandon Taylor Apr 18 '18 at 13:51
  • Look into this https://www.w3schools.com/jsref/jsref_encodeURI.asp – Anand Murali Apr 18 '18 at 13:57
  • I tried with the below url as you said- escaped with %2F- http://localhost:65172/api/schedule/schedulinglevelpool/day/2018-04-18/utility/EQB/pool/EQB%2FEQT%20LOCAL- still failed – Prasad Nair Apr 18 '18 at 14:02
  • Did you un-escape the character in the endpoint code? – Brandon Taylor Apr 18 '18 at 14:09
  • What does the API endpoint routing code look like? – Brandon Taylor Apr 18 '18 at 14:14
  • config.Routes.MapHttpRoute( name: "MyApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); – Prasad Nair Apr 18 '18 at 14:31
  • Failed to load http://localhost:65172/api/schedule/schedulinglevelpool/day/2018-04-19/utility/EQB/pool/EQB/EQT%20LOCAL: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 404.- this is the error message – Prasad Nair Apr 18 '18 at 14:37
  • Sounds like the format of the request parameters is correct, but you don't have CORS enabled. – Brandon Taylor Apr 18 '18 at 14:49
  • public static void Register(HttpConfiguration config) { var cors = new EnableCorsAttribute("*", "*", "*"); //cors.SupportsCredentials = true; config.EnableCors(cors); config.MapHttpAttributeRoutes(); config.Filters.Add(new ModelStateValidatorFilter()); UnityConfig.RegisterComponents(); SetJsonCamelCaseSerializer(config);- CORS enabled – Prasad Nair Apr 18 '18 at 15:35

0 Answers0