I am using web api MVC4. In the get method I will pass the string parameter, which will have space. During execution it gives error.
my WebApiConfig is like below
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "FindDetailsByCountry",
routeTemplate: "api/{controller}/FindDetailsByCountry/{country}",
defaults: new { country = RouteParameter.Optional },
constraints: new { country = @"^[a-z]+$" }
);
Now when I run the application
Case 1
input : .../api/contact/
output :
[{"Name":"Ashok","Age":60,"Country":"India"},{"Name":"Nargis","Age":30,"Country":"India"},{"Name":"Nargis","Age":35,"Country":"Iran"},{"Name":"Steve","Age":50,"Country":"South Africa"}]
Case 2
input : .../api/contact/FindDetailsByCountry/india
output :
[{"Name":"Ashok","Age":60,"Country":"India"},{"Name":"Nargis","Age":30,"Country":"India"}]
Case 3
input : .../api/contact/FindDetailsByCountry/South Africa
output :
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable
For case 3, I am getting error. I have checked using these options
- ...api/contact/FindDetailsByCountry/South+Africa
- ..api/contact/FindDetailsByCountry/South%20Africa
- ../api/contact/FindDetailsByCountry/"South Africa"
- ../api/contact/FindDetailsByCountry/'South Africa'
Still it is giving the same error.
Actually I will use the output in my android application.
In android also I have used URLEncoder.encode("South Africa", "UTF-8")
. But no result.
Can any one tell me how to pass the parameter South Africa ?
Thank you so much ps2goat for my previous question. It works now.
Thanks