日期:2014-05-18 浏览次数:20796 次
var SentMessage = 获取要发送的消息体(); var HttpWebRequest hp = (HttpWebRequest)WebRequest.Create(url); hp.Method = "POST"; hp.ContentType = "text/xml"; hp.ServicePoint.Expect100Continue = false; var sentBuff = Encoding.UTF8.GetBytes(SentMessage); hp.ContentLength = sentBuff.Length; using (var sw = hp.GetRequestStream()) { sw.Write(sentBuff, 0, sentBuff.Length); sw.Flush(); using (var wr = hp.GetResponse()) { using (var sr = new StreamReader(wr.GetResponseStream(), Encoding.UTF8)) { ReceivedXml = sr.ReadToEnd(); } } }
------解决方案--------------------
在windows服务中
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“”);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
Console.Write(sr.ReadToEnd());
sr.Close();
response.Close();
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
Byte[] pageData = wc.DownloadData("");
string html= System.Text.Encoding.Default.GetString(pageData);