我将xml / cxml文档发布到网上的网址。当我发布它时,我收到错误“连接被重置”。我想发布代码,以确保他们没有错误。 stXML是xml文档。
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
byte[] postDataBytes = Encoding.ASCII.GetBytes(stXML);
req.Method = "POST";
req.ContentLength = postDataBytes.Length;
// req.ContentType = "text/XML-urlencoded";
Stream requestStream = req.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);
requestStream.Close();
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.Default);
string strRet = responseReader.ReadToEnd();
Response.Write(strRet);
Response.Close();
答案 0 :(得分:0)
也许您的标题存在问题。 我会避免使用HttpWebRequest增加复杂性,只使用System.Net.WebClient。
string response = new WebClient().UploadString(uri, stXML);