wm6.5 如何与WebServer 进行数据交互,我用HttpWebResponse 报500错误
疯狂农夫 2011-04-15 01:04:50 public System.Xml.XmlDocument HttpWebReuqest(string f_url, string f_parameter, ContentType contenttype)
{
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create
(f_url);
httpWebRequest.Timeout = 180000;
httpWebRequest.AllowWriteStreamBuffering = true;
httpWebRequest.Timeout = 3000;
httpWebRequest.Method = "POST";
shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
byte[] SomeBytes = System.Text.Encoding.Default.GetBytes(f_parameter);//传递的值
httpWebRequest.ContentLength = SomeBytes.Length;
System.IO.Stream newStream = httpWebRequest.GetRequestStream();//把传递的值写到流中
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();//必须要关闭 请求
System.Net.HttpWebResponse httpWebResponse = null;
try
{
httpWebRequest.ContentType = ContentType.text.ToString();
httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
}
catch (System.Net.WebException ex)
{
throw ex;
// httpWebResponse = (System.Net.HttpWebResponse)ex.Response;
}
System.IO.Stream stream = httpWebResponse.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8);
string respHTML = reader.ReadToEnd();
xmldoc.LoadXml(respHTML);
stream.Close();
return xmldoc;
}