我正在在线将 xml/cxml 文档发布到 url。当我发布它时,我收到错误“连接已重置”。我想发布代码以确保他们没有犯错。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();