为什么我以post方式提交数的时候,老是出错,:远程服务器返回错误: (405) 不允许的方法。
private void RequestPost()
{
string url = "http://www.google.com";
Uri myuri=new Uri(url);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string LoginInfo ="test=test";
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes (LoginInfo);
req.Method ="POST";
req.ProtocolVersion=HttpVersion.Version10;
req.AllowAutoRedirect=true;
req.MaximumAutomaticRedirections=10;
req.Accept=@"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
req.ContentType = "application/x-www-form-urlencoded";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322)";

req.RequestUri=myuri;
req.ContentLength = requestBytes.Length;

Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes,0,requestBytes.Length);
requestStream.Close(); HttpWebResponse res=null;

try
{
res = (HttpWebResponse)req.GetResponse();
}
catch(WebException ae)
{
textBox2.Text=ae.Message;
return;
}
cookies=req.CookieContainer.GetCookies(myuri);

StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd();

sr.Close();
res.Close(); }