Grant Killian was converting a classic ASP application into .NET. He wasn't satisfied with interop and was wondering about a replacement for the xmlhttp approach from MSXML (pre-.NET). Here is the code:
XMLHTTP obj = new MSXML2.XMLHTTP();
obj.open( "POST", strURL, false, strUid, strPwd );
obj.setRequestHeader( "Content-Type","application/x-www-form-urlencoded" );
obj.send( strXMLMessage );
if( obj.status != 200 ) {
//unsuccessful . . .
}
else {
//success . . .
obj.responseText;
}
obj = null;
Paul suggested looking at System.Net.HttpWebRequest and System.Net.HttpWebResponse. To make a long story short, here's the .NET port of xmlhttp:
HttpWebRequest req = ( HttpWebRequest )WebRequest.Create( strUrl );
req.ContentType = "application/x-www-form-urlencoded";
req.Method= "POST";
System.IO.Stream stream = req.GetRequestStream();
string strXML = getXMLString();
byte[] arrBytes = System.Text.ASCIIEncoding.ASCII.GetBytes( strXML );
stream.Write( arrBytes, 0, arrBytes.Length );
stream.Close();
WebResponse resp = req.GetResponse();
Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader( respStream, System.Text.Encoding.ASCII );
string strResponse = rdr.ReadToEnd();
Posted
Thu, Jul 17 2003 4:48 PM
by
Darrell Norton