public static HttpWebRequest MakeHttpPost(string url, string httpKeyValue)
        {
            string         result = "";
            HttpWebRequest req    = (HttpWebRequest)WebRequest.Create(url);

            req.Timeout     = 5000;
            req.Method      = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.Accept      = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
            req.UserAgent   = useragent;
            req.Headers.Add("Accept-Language", "zh,zh-CN;q=0.9;q=0.9");
            //req.Connection = "Keep-Alive";
            byte[] data = Encoding.UTF8.GetBytes(httpKeyValue);
            req.ContentLength     = data.Length;
            req.AllowAutoRedirect = false;
            if (null != BeforeRequestSend)
            {
                BeforeRequestSend.Invoke(req, new HttpRequestCreatedEventArgs(req));
            }
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }
            return(req);
        }
Beispiel #2
0
        public static HttpWebRequest MakeHttpGet(string url, string httpKeyValue)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + "?" + httpKeyValue);

            req.Timeout           = 5000;
            req.Method            = "GET";
            req.AllowAutoRedirect = false;
            if (null != BeforeRequestSend)
            {
                BeforeRequestSend.Invoke(req, new HttpRequestCreatedEventArgs(req));
            }
            return(req);
        }
Beispiel #3
0
        public static HttpWebRequest MakeHttpGet(string url, string httpKeyValue)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + "?" + httpKeyValue);

            req.Timeout   = 5000;
            req.Method    = "GET";
            req.Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
            req.UserAgent = useragent;
            req.Headers.Add("Accept-Language", "zh,zh-CN;q=0.9;q=0.9");
            //req.Connection = "Keep-Alive";
            req.AllowAutoRedirect = false;
            if (null != BeforeRequestSend)
            {
                BeforeRequestSend.Invoke(req, new HttpRequestCreatedEventArgs(req));
            }
            return(req);
        }
Beispiel #4
0
        public static HttpWebRequest MakeHttpPost(string url, string httpKeyValue)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            req.Timeout     = 5000;
            req.Method      = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] data = Encoding.UTF8.GetBytes(httpKeyValue);
            req.ContentLength     = data.Length;
            req.AllowAutoRedirect = false;
            if (null != BeforeRequestSend)
            {
                BeforeRequestSend.Invoke(req, new HttpRequestCreatedEventArgs(req));
            }
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }
            return(req);
        }