c# - HttpRequestMessage UserAgent with Colon -
i'm trying send request has user agent set colon in it, httprequestmessage
complaining colon invalid character.
the exact code looks this:
httpclient client = new httpclient(); var request = new httprequestmessage() { requesturi = new uri("some-uri"), method = httpmethod.post }; request.headers.add("user-agent", "sample:text"); // send request...
i looked through this post can see ebnf of user agent , this rfc specifies ctl is.
the first link says following valid user agent:
token = 1*<any char except ctls or separators>
and second link defines ctl as:
any us-ascii control character (octets 0 - 31) , del (127)
but, colon (:
) 58 on ascii table, don't see why problem.
i assumed httprequestmessage
not colons in because it's not escaped -- thinks it's separator. tried escaping in single quotes, double quotes, etc.
is there way escape i'm missing?
or in other words, how send colon (:
) in user agent header of httprequestmessage
?
this turned out escaping issue suspected. doesn't seem httprequestmessage
handles automatic escaping.
i'm able use uri.escapedatastring()
convert colon before adding user-agent
header. when process user-agent on endpoint, have use uri.unescapedatastring()
not pretty, seems work.
Comments
Post a Comment