0

我正在使用 HTTP POST 将 XML 数据发送到指定的 URL。预期的响应是 XML 格式。但我收到的是 HTML 代码而不是 XML。我正在发送我的示例邮政编码。

string postData = null;
postData = "NETCONNECT_TRANSACTION=" + System.Web.HttpUtility.UrlEncode(xdoc.ToString());

HttpWebRequest experianRequest = (HttpWebRequest)WebRequest.Create("some url");
experianRequest.Method = "POST";
experianRequest.ContentType = "application/x-www-form-urlencoded";
string UserIDFormated = "username:password";
experianRequest.Headers.Add("Authorization: BASIC" + ConvertToBase64String(UserIDFormated));
experianRequest.Timeout = 100000;
experianRequest.KeepAlive = false;
experianRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;

System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteData;
byteData = encoding.GetBytes(postData);
experianRequest.AllowAutoRedirect = true;
experianRequest.ContentLength = byteData.Length;
Stream newStream = experianRequest.GetRequestStream();
newStream.Write(byteData, 0, byteData.Length);
newStream.Close();

HttpWebResponse experianResponse = (HttpWebResponse)experianRequest.GetResponse();

StreamReader reader = new StreamReader(experianResponse.GetResponseStream(), Encoding.UTF8);
//XmlTextReader objxml = new XmlTextReader(newStream2);
//XmlDocument xdocresponse = new XmlDocument();
//xdocresponse.Load(experianResponse.GetResponseStream());
//string root = xdocresponse.DocumentElement.OuterXml;
//XDocument xdocresponse = XDocument.Load(objxml);
//objxml.Close();
//experianResponse.Close();
//StreamReader reader = new StreamReader(newStream2);
string responseFromServer = reader.ReadToEnd();
reader.Close();
//newStream.Close();
experianResponse.Close();
4

0 回答 0