public static void AsyncPost(string url, string PostData, AsyncPostAction action, string Referer = "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2", int timeout = 100000) { HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; req.CookieContainer = cookies; req.ContentType = "application/x-www-form-urlencoded"; req.Method = "POST"; req.Referer = Referer; req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2372.400 QQBrowser/9.5.10548.400"; //req.UserAgent = "Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0) Gecko/20100101 Firefox/47.0"; req.Proxy = null; req.ProtocolVersion = HttpVersion.Version11; req.ContinueTimeout = timeout; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(PostData); Stream stream = req.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); AsyncPostData dat = new AsyncPostData(); dat.req = req; dat.asyncPostAction = action; req.BeginGetResponse(new AsyncCallback(AsyncPostResponesProceed), dat); }
private static void AsyncPostResponesProceed(IAsyncResult ar) { StreamReader reader = null; AsyncPostData dat = ar.AsyncState as AsyncPostData; HttpWebRequest req = dat.req; HttpWebResponse res = req.GetResponse() as HttpWebResponse; reader = new StreamReader(res.GetResponseStream()); string temp = reader.ReadToEnd(); res.Close(); req.Abort(); dat.asyncPostAction(temp); }