I am posting a xml/cxml document to a url online. When I post it I get error “Connection Was Reset”. I wanted to post the code to make sure their was no mistake being made.
stXML is the xml document.
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();
Perhaps there’s an issue with your headers.
I would avoid the added complexity of using HttpWebRequest and just use System.Net.WebClient.