I have a problem when a url contains Chinese characters. It doesn't happen every time, but when it does, I find the following errors in the event log:
EventMessage
No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459)
EventStackTrace
System.ArgumentOutOfRangeException: No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
at System.Web.Hosting.IIS7WorkerRequest.ReadRequestHeaders()
at System.Web.Hosting.IIS7WorkerRequest.GetKnownRequestHeader(Int32 index)
at System.Web.HttpRequest.FillInHeadersCollection()
at System.Web.HttpRequest.get_Headers()
It seems the exception was thrown in the native method.
It seems like this happens when a Cookie or other header contains a unicode character. This blog entry may shed some light on the problem and a solution.
I solved it by send data as Base64String
, in my case it is an object:
byte[] bytes = Encoding.UTF8.GetBytes(Json.Convert(myObject))
client.DefaultRequestHeaders.Add("data" , Convert.ToBase64String(bytes));
User contributions licensed under CC BY-SA 3.0