![301免备案跳转微信公众号 301免备案跳转微信公众号](/blog/d/file/p/2023/11-06/384a0f88dc69e6f0b9276fec739fb818.png)
![腾讯云服务器大促销。](/blog/d/file/p/2023/06-06/8f2af9e8846e4a93cc2a3890462510dc.png)
![华为服务器](/blog/d/file/p/2023/07-25/08518ffe66f6cea5a59993d8b8d33b96.jpg)
1、HttpWebRequest登录方法:
public static string HttpPost(string Url, string PostData, string cookies,string UA,out string result)
{
result = null;
HttpWebRequest request = null;
HttpWebResponse response = null;
try
{
request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
byte[] data = Encoding.UTF8.GetBytes(PostData);
request.ContentType = "application/x-www-form-urlencoded";
request.ServicePoint.ConnectionLimit = 3000;
request.UserAgent = UA;
request.ContentLength = data.Length;
request.Headers.Add("cookie", cookies);
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
result = reader.ReadToEnd();
reader.Close();
request.Abort();
response.Close();
return result;
}
catch (Exception ex)
{
if (request != null) request.Abort();
if (response != null) response.Close();
MessageBox.Show("报错,原因:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return string.Empty;
}
}
在需要的地方用如下代码调用即可:
HttpPost(Url, PostData, cookies, UA, out result);
![301免备案跳转微信公众号 301免备案跳转微信公众号](/blog/d/file/p/2023/11-06/384a0f88dc69e6f0b9276fec739fb818.png)
![华为服务器](/blog/d/file/p/2023/07-25/08518ffe66f6cea5a59993d8b8d33b96.jpg)
![腾讯云服务器大促销。](/blog/d/file/p/2023/06-06/8f2af9e8846e4a93cc2a3890462510dc.png)
文章评论 本文章有个评论