110,536
社区成员
发帖
与我相关
我的任务
分享
string val = string.Empty;
byte[] buf = Encoding.GetEncoding("utf-8").GetBytes("1111111111");
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://www.baidu.com/"));
request.ProtocolVersion = HttpVersion.Version10;
request.KeepAlive = false;
request.SendChunked = false;
System.Net.ServicePointManager.Expect100Continue = false;
request.Expect = null;
request.Timeout = 60 * 1000;
request.ContentType = "text/xml";
request.Method = "POST";
request.ContentLength = buf.Length;
Stream stream = request.GetRequestStream();
stream.Write(buf, 0, buf.Length);
stream.Flush();
stream.Close();
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); ///, Encoding.GetEncoding(encoding));
val = reader.ReadToEnd();
reader.Close();
response.Close();
}
catch (Exception ex)
{
val = "";
//MessageBox.Show(ex.Message + "\r\n" + ex.ToString());
MessageBox.Show(ex.ToString());
}
//获取请求的内容
HttpWebRequest hwr = ( HttpWebRequest ) HttpWebRequest.Create( new Uri( EntryUrl ) );
hwr.Method = "POST";
hwr.KeepAlive = false;
hwr.ContentType = "application/x-www-form-urlencoded";
hwr.ContentLength = b.Length;
hwr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
hwr.CookieContainer = cookieCon;
//// 发送数据
using( Stream s = hwr.GetRequestStream() )
{
s.Write( b, 0, b.Length );
}