来大神!!HttpWebRequest发送Post请求出现403错误!!一个下午了!!求大神
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(parmstr);
// Prepare web request...
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(url+parmstr);
myRequest.Method = "POST";
myRequest.Timeout = 1000 * 60 * 10 * 10;
myRequest.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT)";
myRequest.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"); ;
myRequest.Credentials = CredentialCache.DefaultCredentials;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.CookieContainer = myCookieContainer;
myRequest.ContentLength = data.Length;
myRequest.KeepAlive =false;
myRequest.ProtocolVersion = HttpVersion.Version10;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
// Get response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
求大神!! 新浪,网易这种网站就提示出错误,用Get的没问题,一用Post就提示403错误。