当前位置: 首页>>代码示例>>C#>>正文


C# Request.SetCookie方法代码示例

本文整理汇总了C#中IronWASP.Request.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# Request.SetCookie方法的具体用法?C# Request.SetCookie怎么用?C# Request.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IronWASP.Request的用法示例。


在下文中一共展示了Request.SetCookie方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRedirect

        public Request GetRedirect(Response Res)
        {
            if (Res.Code == 301 || Res.Code == 302 || Res.Code == 303 || Res.Code == 307)
            {
                if (Res.Headers.Has("Location"))
                {
                    string NewUrl = Res.Headers.Get("Location");
                    Request NewReq = new Request(this.FullURL);
                    if (NewUrl.StartsWith("/"))
                    {
                        NewReq.URL = NewUrl;
                    }
                    else if (NewUrl.StartsWith("http://") || NewUrl.StartsWith("https://"))
                    {
                        NewReq.FullURL = NewUrl;
                    }
                    else if (NewUrl.StartsWith(".."))
                    {
                        int DirBackNumber = 0;
                        List<string> UpdatedNewUrlPathParts = NewReq.UrlPathParts;
                        List<string> NewUrlPathParts = new List<string>(NewUrl.Split('/'));
                        if (!NewReq.Url.EndsWith("/") && UpdatedNewUrlPathParts.Count > 0) UpdatedNewUrlPathParts.RemoveAt(UpdatedNewUrlPathParts.Count - 1);
                        foreach (string NewUrlPathPart in NewUrlPathParts)
                        {
                            if (NewUrlPathPart.Equals(".."))
                                DirBackNumber++;
                            else
                                break;
                        }

                        while (UpdatedNewUrlPathParts.Count > 0 && DirBackNumber > 0)
                        {
                            UpdatedNewUrlPathParts.RemoveAt(UpdatedNewUrlPathParts.Count - 1);
                            if (NewUrlPathParts.Count > 0) NewUrlPathParts.RemoveAt(0);
                            DirBackNumber--;
                        }
                        UpdatedNewUrlPathParts.AddRange(NewUrlPathParts);
                        NewReq.UrlPathParts = UpdatedNewUrlPathParts;
                        if (NewUrl.EndsWith("/"))
                        {
                            if (!NewReq.Url.EndsWith("/")) NewReq.Url = NewReq.Url + "/";
                        }
                        else
                        {
                            if (NewReq.Url.EndsWith("/") && NewReq.Url.Length > 1) NewReq.Url = NewReq.Url.TrimEnd(new char[] { '/' });
                        }
                    }
                    else
                    {
                        List<string> NewUrlPathParts = NewReq.UrlPathParts;
                        if (!NewReq.Url.EndsWith("/") && NewUrlPathParts.Count > 0) NewUrlPathParts.RemoveAt(NewUrlPathParts.Count - 1);
                        NewReq.UrlPathParts = NewUrlPathParts;
                        if (!NewReq.Url.EndsWith("/")) NewReq.Url = NewReq.Url + "/";
                        NewReq.Url = NewReq.Url + NewUrl;
                    }
                    //this check is needed since sometimes the redirect can go to a different domain
                    if (this.Host == NewReq.Host)
                    {
                        NewReq.CookieString = this.CookieString;
                        NewReq.SetCookie(Res.SetCookies);
                    }
                    return NewReq;
                }
            }
            return null;
        }
开发者ID:moon2l,项目名称:IronWASP,代码行数:66,代码来源:Request.cs

示例2: Crawl

        void Crawl(Request Req, int Depth, bool Scraped)
        {
            if (Stopped) return;
            if (Depth > MaxDepth) return;
            if (WasCrawled(Req)) return;
            if (!CanCrawl(Req)) return;

            lock (PageSignatures)
            {
                PageSignatures.Add(GetPageSignature(Req));
            }

            Req.Source = RequestSource.Probe;
            Req.SetCookie(Cookies);
            if (UserAgent.Length > 0) Req.Headers.Set("User-Agent", UserAgent);
            Response Res = Req.Send();
            Cookies.Add(Req, Res);
            bool Is404File = IsA404(Req, Res);

            if (!Res.IsHtml)
            {
                try
                {
                    Res.ProcessHtml();
                }
                catch
                {
                    return;
                }
            }

            if (Depth + 1 > MaxDepth) return;
            List<Request> LinkClicks = GetLinkClicks(Req, Res);
            foreach (Request LinkClick in LinkClicks)
            {
                AddToCrawlQueue(LinkClick, Depth + 1, true);
            }

            List<Request> FormSubmissions = GetFormSubmissionRequests(Req, Res);
            foreach (Request FormSubmission in FormSubmissions)
            {
                AddToCrawlQueue(FormSubmission, Depth + 1, true);
            }

            Request DirCheck = Req.GetClone();
            DirCheck.Method = "GET";
            DirCheck.Body.RemoveAll();
            DirCheck.Url = DirCheck.UrlDir;

            if (!Req.Url.EndsWith("/"))
            {
                AddToCrawlQueue(DirCheck, Depth + 1, false);
            }

            if (PerformDirAndFileGuessing && !Is404File)
            {
                foreach (string File in FileNamesToCheck)
                {
                    Request FileCheck = DirCheck.GetClone();
                    FileCheck.Url = FileCheck.Url + File;
                    AddToCrawlQueue(FileCheck, Depth + 1, false);
                }

                foreach (string Dir in DirNamesToCheck)
                {
                    Request DirectoryCheck = DirCheck.GetClone();
                    DirectoryCheck.Url = DirectoryCheck.Url + Dir + "/";
                    AddToCrawlQueue(DirectoryCheck, Depth + 1, false);
                }
            }

            if (Scraped || !Is404File)
            {
                lock (CrawledRequests)
                {
                    CrawledRequests.Enqueue(Req);
                }
                IronUpdater.AddToSiteMap(Req);
            }
        }
开发者ID:msaindane,项目名称:IronWASP,代码行数:80,代码来源:Crawler.cs

示例3: GetLinkClicks

 List<Request> GetLinkClicks(Request Req, Response Res)
 {
     List<Request> LinkClicks = new List<Request>();
     List<string> Links = GetLinks(Req, Res);
     foreach (string Link in Links)
     {
         try
         {
             Request LinkReq = new Request(Link);
             LinkReq.SetCookie(Cookies);
             LinkClicks.Add(LinkReq);
         }
         catch { }
     }
     return LinkClicks;
 }
开发者ID:msaindane,项目名称:IronWASP,代码行数:16,代码来源:Crawler.cs

示例4: GetRedirect

        public Request GetRedirect(Response Res)
        {
            if (Res.IsRedirect)
            {
                if (Res.Headers.Has("Location"))
                {
                    string NewUrl = Res.Headers.Get("Location");
                    Request NewReq = new Request(this.FullURL);
                    if (NewUrl.StartsWith("/"))
                    {
                        NewReq.URL = NewUrl;
                    }
                    else if (NewUrl.StartsWith("http://") || NewUrl.StartsWith("https://"))
                    {
                        NewReq.FullURL = NewUrl;
                    }
                    else if (NewUrl.StartsWith(".."))
                    {
                        int DirBackNumber = 0;
                        List<string> UpdatedNewUrlPathParts = NewReq.UrlPathParts;
                        List<string> NewUrlPathParts = new List<string>(NewUrl.Split('/'));
                        if (!NewReq.Url.EndsWith("/") && UpdatedNewUrlPathParts.Count > 0) UpdatedNewUrlPathParts.RemoveAt(UpdatedNewUrlPathParts.Count - 1);
                        foreach (string NewUrlPathPart in NewUrlPathParts)
                        {
                            if (NewUrlPathPart.Equals(".."))
                                DirBackNumber++;
                            else
                                break;
                        }

                        while (UpdatedNewUrlPathParts.Count > 0 && DirBackNumber > 0)
                        {
                            UpdatedNewUrlPathParts.RemoveAt(UpdatedNewUrlPathParts.Count - 1);
                            if (NewUrlPathParts.Count > 0) NewUrlPathParts.RemoveAt(0);
                            DirBackNumber--;
                        }
                        UpdatedNewUrlPathParts.AddRange(NewUrlPathParts);
                        NewReq.UrlPathParts = UpdatedNewUrlPathParts;
                        if (NewUrl.EndsWith("/"))
                        {
                            if (!NewReq.Url.EndsWith("/")) NewReq.Url = NewReq.Url + "/";
                        }
                        else
                        {
                            if (NewReq.Url.EndsWith("/") && NewReq.Url.Length > 1) NewReq.Url = NewReq.Url.TrimEnd(new char[] { '/' });
                        }
                    }
                    else
                    {
                        List<string> NewUrlPathParts = NewReq.UrlPathParts;
                        if (!NewReq.Url.EndsWith("/") && NewUrlPathParts.Count > 0) NewUrlPathParts.RemoveAt(NewUrlPathParts.Count - 1);
                        NewReq.UrlPathParts = NewUrlPathParts;
                        if (!NewReq.Url.EndsWith("/")) NewReq.Url = NewReq.Url + "/";
                        NewReq.Url = NewReq.Url + NewUrl;
                    }
                    //this check is needed since sometimes the redirect can go to a different domain
                    if (this.Host == NewReq.Host)
                    {
                        NewReq.CookieString = this.CookieString;
                        NewReq.SetCookie(Res.SetCookies);
                    }
                    //Update the Source of the redirect request with the value of the current request
                    NewReq.Source = this.Source;
                    if (this.Source.Equals("Scan"))
                        NewReq.ScanID = this.ScanID;
                    //Update general headers associated with the current request in to the header of the redirect request
                    foreach (string HeaderName in this.Headers.GetNames())
                    {
                        if (!(HeaderName.Equals("Host", StringComparison.OrdinalIgnoreCase) || HeaderName.Equals("Content-Length", StringComparison.OrdinalIgnoreCase) || HeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase) || HeaderName.Equals("Cookie", StringComparison.OrdinalIgnoreCase)))
                        {
                            foreach (string HeaderValue in this.Headers.GetAll(HeaderName))
                            {
                                NewReq.Headers.Add(HeaderName, HeaderValue);
                            }
                        }
                    }
                    return NewReq;
                }
            }
            return null;
        }
开发者ID:herotheo,项目名称:IronWASP,代码行数:81,代码来源:Request.cs

示例5: GetRedirects

 public static List<Request> GetRedirects(Request Req, Response Res, CookieStore Cookies)
 {
     List<Request> Redirects = new List<Request>();
     List<string> RedirectUrls = GetRedirectUrls(Req, Res);
     foreach (string RedirectUrl in RedirectUrls)
     {
         try
         {
             Request RedirectReq = new Request(RedirectUrl);
             RedirectReq.SetCookie(Cookies);
             Redirects.Add(RedirectReq);
         }
         catch { }
     }
     return Redirects;
 }
开发者ID:mskr30,项目名称:IronWASP,代码行数:16,代码来源:Crawler.cs

示例6: Update

 public virtual Request Update(Request Request, Response Response)
 {
     Request.SetCookie(Response);
     return Request;
 }
开发者ID:welias,项目名称:IronWASP,代码行数:5,代码来源:SessionPlugin.cs

示例7: ReadFromStore

 public static void ReadFromStore(Request Req)
 {
     Req.SetCookie(StaticCookieStore);
 }
开发者ID:0ks3ii,项目名称:IronWASP,代码行数:4,代码来源:CookieStore.cs

示例8: GetRedirect

 public Request GetRedirect(Response Res)
 {
     if (Res.Code == 301 || Res.Code == 302 || Res.Code == 303 || Res.Code == 307)
     {
         if (Res.Headers.Has("Location"))
         {
             string NewUrl = Res.Headers.Get("Location");
             Request NewReq = new Request(this.FullURL);
             if (NewUrl.StartsWith("/"))
             {
                 NewReq.URL = NewUrl;
                 return NewReq;
             }
             if (NewUrl.StartsWith("http://") || NewUrl.StartsWith("https://"))
             {
                 NewReq.FullURL = NewUrl;
                 if (this.Host == NewReq.Host)
                 {
                     NewReq.CookieString = this.CookieString;
                     NewReq.SetCookie(Res.SetCookies);
                 }
                 return NewReq;
             }
         }
     }
     return null;
 }
开发者ID:msaindane,项目名称:IronWASP,代码行数:27,代码来源:Request.cs


注:本文中的IronWASP.Request.SetCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。