Invalid character in HttpWebResponse causing 400: Bad Request

IrinaMilay

New Member
I have a web application which handles orders from customers. There's a problem when updating a new order, which gives me the following information: \[quote\] The server encountered an error processing the request. The exception message is 'The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:order. The InnerException message was 'There was an error deserializing the object of type Service.Order. Encountered invalid character ' '.'." \[/quote\]I suspect this is caused by a new username which has an underscore in it's name like so: Test_NameCould this be true and how do I avoid it in that case?The code looks like this: \[code\] // Create the data we want to send data = "http://stackoverflow.com/questions/14584584/{/"order\":{\"OrderId\":\"" + OrderId + "\"," + "\"UserId\":\"" + userId + "\"," + "\"ContractorId\":\"" + contractorId + "\"," + "\"ContractInfo\":\"" + contractInfo + "\"}}"; // Create a byte array of the data we want to send byteData = http://stackoverflow.com/questions/14584584/Encoding.UTF8.GetBytes(data); // Set the content length in the request headers request.ContentLength = byteData.Length; // Write data using (Stream postStream = request.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } try { using (var response2 = (HttpWebResponse) request.GetResponse()) **-> crashes here** { } } catch (WebException e) { }\[/code\]
 
Back
Top