来大神!!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错误。
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错误。
...全文
相关推荐
C#模拟http 发送post或get请求的简单实例
以下是一个简单的POST请求实例:```csharpprivate string HttpPost(string Url, string postDataStr){ // 创建HttpWebRequest
VB实现Web QQ网页登录POST请求实战
是 .NET Framework 中System.Net命名空间下用于发起HTTP/HTTPS请求的核心类。它继承自抽象基类WebRequest,专门针对HTTP协议进行优化设计,支持GET、POST、PUT、DELETE等多种方法,并允许开发者精细控制每一个请求细节,例如自定义头部、设置代理、管理身份验证凭证及配置超时策略。相较于其他.NET提供的HTTP客户端类型(如WebClient和后来的HttpClient),的最大优势在于其高度可配置性和同步/异步双模式支持。
C#(Csharp)多线程HTTP并发请求(HttpWebRequest)采集蜘蛛
它会从待下载集合中取出第一个URL,将其移动到已下载集合,并创建一个HttpWebRequest对象,设置请求方法、接受类型、用户代理等属性,然后使用异步请求方法开始请求。5.
C#基于HttpWebRequest实现发送HTTP请求的方法分析
### POST请求POST请求用于向服务器发送数据,常用于提交表单或上传数据。
浅谈C#中HttpWebRequest与HttpWebResponse的使用方法
- 发送数据:对于POST请求,可以通过GetRequestStream()获取上传数据的流,并用StreamWriter写入数据。


