c# - Is it possible to have a REST url parameter with an ampersand? -


using system.servicemodel libraries routing, have rest service simple template looks

"{searchterm}?opt={somesearchopt}

so call like:

http://myhost.contoso.com/searchapi/river%20expeditions

to search phrase "river expeditions" no options.

this accepts search phrase , returns results. works fine. however, if searching phrase contains literal ampersand, such "lewis&clark", tried obvious of url encoding ampersand

lewis%26clark

but request never routed, server returns 400 bad request. clear being interpreted query string delimiter, , makes request invalid since particular template expecting url parameter , has no preceeding '?' delimiter.

since these search phrases may have other restricted characters, expected url encoded client, , when routed, rest api calls httputility.urldecode on parameter. question if there technique getting url encoded ampersand correctly routed rest url parameter , not pre-emptively interpreted , rejected query string delimiter?

update: record, if search term expected query string parameter (not url parameter), sending lewis%26clark works fine. example

http://myhost.contoso.com/searchapi?searchterm=lewis%26clark

so clarify, looking same result when using url parameter in rest template.

this thread has similar question\solution.

as mentioned in answer above link, avoid url encodeding characters in uri , instead put in query string portion.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -