我目前正在尝试将 xml 文件发布到 Web 服务。
这是我当前的代码
var tempFileLocation = @"c:\Temp\";
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(item);
xdoc.Save(tempFileLocation + "\\pcf.xml");
var url = "https://Siteaddress/xml.aspx";
UTF8Encoding encoding = new UTF8Encoding();
byte[] byte1 = encoding.GetBytes(xdoc.InnerXml);
HttpWebRequest submissionRequest = (HttpWebRequest)WebRequest.Create(url);
submissionRequest.KeepAlive = true;
submissionRequest.Method = "POST";
submissionRequest.ContentType = "multipart/form-data";
submissionRequest.ContentLength = byte1.Length;
submissionRequest.Timeout = 10000;
submissionRequest.Headers.Add("Accept-Encoding", "gzip,deflate");
Stream requestStream = submissionRequest.GetRequestStream();
requestStream.Write(byte1, 0, byte1.Length);
requestStream.Close();
XmlDocument responseXMLDocument = new XmlDocument();
HttpWebResponse submissionAcknowledgement = (HttpWebResponse)submissionRequest.GetResponse();
if (submissionAcknowledgement.StatusCode == HttpStatusCode.OK)
{
responseXMLDocument.Load(submissionAcknowledgement.GetResponseStream());
}
然后我收到以下消息。
错误的 Request.Form[pcfxml] - 这应该作为 POST 附加
我应该如何将 xml 文件作为附件发布?