Exemplo n.º 1
0
        public Buf Post(Uri uri, byte[] postData, string referer, string content_type)
        {
            HttpWebRequest r = (HttpWebRequest)HttpWebRequest.Create(uri);

            if (this.NoCookie == false)
            {
                r.CookieContainer = this.cc;
            }
            else
            {
                r.CookieContainer = new CookieContainer();
            }

            if (Str.IsEmptyStr(this.ProxyHostname) == false && this.ProxyPort != 0)
            {
                r.Proxy = new WebProxy(this.ProxyHostname, this.ProxyPort);
            }

            r.UnsafeAuthenticatedConnectionSharing = true;
            r.AllowAutoRedirect = true;
            if (Http1_1 == false)
            {
                r.KeepAlive       = false;
                r.ProtocolVersion = new Version(1, 0);
            }
            r.Timeout     = this.timeoutInt;
            r.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
            r.Method      = "POST";

            if (this.UserAgent != null)
            {
                r.UserAgent = this.UserAgent;
            }

            if (Str.IsEmptyStr(referer) == false)
            {
                r.Referer = referer;
            }

            Buf data = new Buf(postData);

            r.ContentType   = content_type;
            r.ContentLength = data.Size;

            Stream st2 = r.GetRequestStream();

            st2.Write(data.ByteData, 0, (int)data.Size);
            st2.Flush();
            st2.Close();

            WebResponse res = r.GetResponse();

            Stream st = res.GetResponseStream();

            return(Buf.ReadFromStream(st));
        }
Exemplo n.º 2
0
        public Buf Get(Uri uri)
        {
            HttpWebRequest r = (HttpWebRequest)HttpWebRequest.Create(uri);

            if (this.NoCookie == false)
            {
                r.CookieContainer = this.cc;
            }
            else
            {
                r.CookieContainer = new CookieContainer();
            }

            if (Str.IsEmptyStr(this.ProxyHostname) == false && this.ProxyPort != 0)
            {
                r.Proxy = new WebProxy(this.ProxyHostname, this.ProxyPort);
            }

            r.UnsafeAuthenticatedConnectionSharing = true;
            r.AllowAutoRedirect = true;
            if (Http1_1 == false)
            {
                r.KeepAlive       = false;
                r.ProtocolVersion = new Version(1, 0);
            }
            r.Timeout     = this.timeoutInt;
            r.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
            r.Method      = "GET";

            if (this.UserAgent != null)
            {
                r.UserAgent = this.UserAgent;
            }

            WebResponse res = r.GetResponse();

            Stream st = res.GetResponseStream();

            return(Buf.ReadFromStream(st));
        }