There is no Unicode byte order mark. Cannot switch to Unicode.
-
Hello, I am receiving the error message:
There is no Unicode byte order mark. Cannot switch to Unicode
in this XML segment:
There is no Unicode byte order mark. Cannot switch to Unicode.
It occurs on the final line of this method:
private async Task QueryOrders(string key, string accountName)
{
string XMLstring = CalculateOrderQueryXML(key, accountName);
StringContent stringcontent = new StringContent(XMLstring);
stringcontent.Headers.ContentType.MediaType = "text/XML";
HttpResponseMessage response = await http.PostAsync("https://www.mywebsite.com/shared/xml/orderquery.rest", stringcontent);/\*string for response\*/ string ResponseString = await response.Content.ReadAsStringAsync(); XmlDocument xml = new XmlDocument(); xml.LoadXml(ResponseString); return xml.OuterXml; }
-
Hello, I am receiving the error message:
There is no Unicode byte order mark. Cannot switch to Unicode
in this XML segment:
There is no Unicode byte order mark. Cannot switch to Unicode.
It occurs on the final line of this method:
private async Task QueryOrders(string key, string accountName)
{
string XMLstring = CalculateOrderQueryXML(key, accountName);
StringContent stringcontent = new StringContent(XMLstring);
stringcontent.Headers.ContentType.MediaType = "text/XML";
HttpResponseMessage response = await http.PostAsync("https://www.mywebsite.com/shared/xml/orderquery.rest", stringcontent);/\*string for response\*/ string ResponseString = await response.Content.ReadAsStringAsync(); XmlDocument xml = new XmlDocument(); xml.LoadXml(ResponseString); return xml.OuterXml; }
Either the remote service is expecting Unicode data, or your generated XML has specified that it's using Unicode. Try sending the request with the Unicode encoding:
string xmlString = CalculateOrderQueryXML(key, accountName);
StringContent stringContent = new StringContent(xmlString, System.Text.Encoding.Unicode, System.Net.Mime.MediaTypeNames.Text.Xml);
using (HttpResponseMessage response = await http.PostAsync("https://www.mywebsite.com/shared/xml/orderquery.rest", stringContent))
{
string responseString = await response.Content.ReadAsStringAsync();
XmlDocument xml = new XmlDocument();
xml.LoadXml(responseString);
return xml.OuterXml;
}If that doesn't work, then you'll need to check the result of your
CalculateOrderQueryXML
method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer