0
我正在嘗試發送XML休息消息,並且它在字段中包含特殊字符。當我解碼時發送它,它正在放?在特殊字符應該在哪裏。xml編碼特殊字符
ServiceUtil.Log(xmlRequest.OuterXml);
TransactionFactory.Response(xmlRequest, ServiceUtil.SERVICE, ExistingReceipt.poNumber);
ServiceUtil.Log("Written to transaction factory.");
objHttpWebRequest = (HttpWebRequest)WebRequest.Create(BrokerDetails.endpoint);
ServiceUtil.Log(string.Format("Endpoint {0}", BrokerDetails.endpoint));
byte[] bytes = Encoding.ASCII.GetBytes(xmlRequest.InnerXml);
objHttpWebRequest.Method = "POST";
objHttpWebRequest.Headers["Authorization"] = string.Concat("Basic ", Convert.ToBase64String(Encoding.Default.GetBytes(string.Format("{0}:{1}", BrokerDetails.username, BrokerDetails.password))));
ServiceUtil.Log(string.Format("User {0}, password {1}", BrokerDetails.username, BrokerDetails.password));
objHttpWebRequest.ContentLength = (long)((int)bytes.Length);
objHttpWebRequest.ContentType = "application/xml; encoding='utf-8'";
objRequestStream = objHttpWebRequest.GetRequestStream();
objRequestStream.Write(bytes, 0, (int)bytes.Length);
objRequestStream.Close();
XmlDocument xmlDoc = new XmlDocument();
objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
ServiceUtil.Log(string.Format("Got status {0}", objHttpWebResponse.StatusCode.ToString()));
if (objHttpWebResponse.StatusCode == HttpStatusCode.OK)
{
objXMLReader = new XmlTextReader(objHttpWebResponse.GetResponseStream());
xmlDoc.Load(objXMLReader);
if (xmlDoc.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
{
xmlDoc = BaseImpl.StripDeclerations(xmlDoc);
}
xmlDoc.LoadXml(xmlDoc.DocumentElement.OuterXml);
objXMLReader.Close();
TransactionFactory.Response(xmlDoc, ServiceUtil.SERVICE, ExistingReceipt.poNumber);
Response = BaseImpl.BuildResponse<GoodsReceivedResponse> (xmlDoc);
ServiceUtil.Log(string.Format("Response {0}", Response.Result));
Transmited = true;
}
else if (Tries <= 4)
{
Response = null;
Tries += 1;
}
else
{
ErrorMessages.AddAnError(new Error(string.Format(ServiceUtil.NULL_RESPONSE, ExistingReceipt.poNumber)));
Response = new GoodsReceivedResponse(ErrorMessages.ErrorMessages);
Transmited = true;
ServiceUtil.Log("No response");
}
這是編碼和發送請求的代碼。
<stockReceivedRequest>
<stockReceived>
<distributorCode>GEO</distributorCode>
<dateReceived>2016-06-10T00:00:00</dateReceived>
<timeReceived>2016-06-10T01:01:01</timeReceived>
<courier>ABC</courier>
<poNumber>1122</poNumber>
<stockDetailReceived>
<stockDetail>
<productCode>G0-4MK</productCode>
<altProductCode />
<productName>Gift set ü</productName>
<quantity>10</quantity>
</stockDetail>
</stockDetailReceived>
這是我們正在嘗試發送XML,這是正在接收什麼。
<?xml version="1.0"?>
<stockReceivedRequest>
<stockReceived>
<distributorCode>GEO</distributorCode>
<dateReceived>2016-06-10T00:00:00</dateReceived>
<timeReceived>2016-06-10T01:01:01</timeReceived>
<courier>ABC</courier>
<poNumber>1119</poNumber>
<stockDetailReceived>
<stockDetail>
<productCode>G0-4MK</productCode>
<altProductCode />
<productName>Gift set ?</productName>
<quantity>10</quantity>
</stockDetail>
</stockDetailReceived>
</stockReceived>
希望有人能夠幫助,如果你有什麼事就問我。
問候
艾丹
您可以使用CData爲此 – Alex