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;
}
...全文
58 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,977

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧