来大神!!HttpWebRequest发送Post请求出现403错误!!一个下午了!!求大神

Dee_XChen Dee_XChen 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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错误。
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
Dee_XChen
C# 111,129 成员 642,538 内容