Пример #1
0
 public HTTPCookie AddCookie(HTTPCookie cookie)
 {
     if (cookie == null)
     {
         return(this);
     }
     return(AddCookie(cookie._Cookie, cookie._Domain));
 }
Пример #2
0
        public HTTPResponse ParseCookie()
        {
            var Header = this.header;

            if (!Header.ContainsKey("Set-Cookie"))
            {
                return(null);
            }
            var ret       = new HTTPCookie();
            var SetCookie = Header["Set-Cookie"];

            Header.Remove("Set-Cookie");
            ret._Domain = "";
            foreach (var cookie in SetCookie.Split(';'))
            {
                try
                {
                    var tmp    = cookie.Split(new char[] { '=' }, 2);
                    var header = tmp[0];
                    var data   = tmp[1];
                    if (header == " domain")
                    {
                        if (ret._Domain == "")
                        {
                            ret._Domain = data;
                        }
                        continue;
                    }
                    ret.AddCookie(header, data, ret._Domain);
                }
                catch (IndexOutOfRangeException e)
                {
                    ret.AddCookie(cookie, null, ret._Domain);
                }
            }
            return(this);
        }
Пример #3
0
 public HTTPCookie AddCookie(Dictionary <string, string> cookie, string domain)
 {
     if (ValidDomain(domain))
     {
         foreach (var item in cookie)
         {
             if (_Cookie.ContainsKey(item.Key))
             {
                 _Cookie[item.Key] = item.Value;
             }
             else
             {
                 _Cookie.Add(item.Key, item.Value);
             }
         }
         return(this);
     }
     else
     {
         HTTPCookie newCookie = new HTTPCookie();
         newCookie._Cookie = cookie;
         return(newCookie);
     }
 }
Пример #4
0
        public HTTPRequest MakeRequest(HTTPMethod?method, string Url, object Addition, HTTPRequest.RequestCallback callback, HTTPCookie cookie = null, HTTPHeader additionHeader = null, string PostData = null)
        {
            Uri path = new Uri(Url);

            if (path.Host != request.Host)
            {
                HTTPOp.Request(method.Value, Url, Addition, callback, cookie, additionHeader, PostData);
                return(null);
            }
            else
            {
                HTTPRequest newRequest = request.CopyTo();
                newRequest.method   = method == null ? newRequest.method : method.Value;
                newRequest.Url      = path.PathAndQuery;
                newRequest.Addition = Addition ?? newRequest.Addition;
                newRequest.Callback = callback ?? newRequest.Callback;
                //newRequest.Cookie = cookie ?? newRequest.Cookie ;
                newRequest.Cookie   = this.cookie?.AddCookie(cookie).GetCookie(path.Host);
                newRequest.PostData = PostData;
                //newRequest.Header = header ?? newRequest.Header ;
                return(newRequest);
            }
        }
Пример #5
0
        public static HTTPError Request(HTTPMethod method, string Url, object Addition, HTTPRequest.RequestCallback callback, HTTPCookie cookie = null, HTTPHeader additionHeader = null, string PostData = null)
        {
            HTTPStateObject state   = new HTTPStateObject();
            HTTPRequest     request = new HTTPRequest()
            {
                method = method
            };
            Uri path = new Uri(Url);

            request.Cookie   = cookie?.GetCookie(path.Host);
            request.Header   = additionHeader;
            request.Callback = callback;
            request.Addition = Addition;
            request.SetUrl(path.Scheme, path.PathAndQuery, path.Host);
            request.PostData = PostData;
            return(Request(request));
        }