0

I am trying to pass a special characters to a custom function in Web API. The function works if I don't pass special characters. The special characters that I am referring to are '#' ,'&' ,....

[HttpGet] [EnableQuery(MaxExpansionDepth = 5)] public IQueryable<Test> QueryTest(string Query) { var dbTest = db.Test.AsQueryable(); return dbTest; } 
2
  • 1
    Which characters are you referring to and what exactly happens? Commented Jan 8, 2019 at 13:59
  • The characters probably have to be encoded in order to be received correctly by the backend and not be treated as something else by the HTTP protocol. Commented Jan 8, 2019 at 14:04

2 Answers 2

1

An option is to use a post method and pass your parameter through a json object in the body message.

[HttpPost] public IQueryable<Test> QueryTest(QueryTestRequest request) { var dbTest = db.Test.AsQueryable(); return dbTest; } public class QueryTestRequest { public string Query {get; set;} } 
Sign up to request clarification or add additional context in comments.

Comments

1

URL encoding is the way to go. This should be done as a default you don't even think of, solves so many issues. Set the Encoding of the WebClient

client.Encoding = Encoding.UTF8; 

1 Comment

Thank you .Where do I need to do that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.