首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTTPWebRequest和CookieContainer

HTTPWebRequest和CookieContainer
EN

Stack Overflow用户
提问于 2012-06-10 04:01:02
回答 1查看 8.8K关注 0票数 0

我创建了一个新的HTTPWebRequest,但是我无法为它分配CookieContainer,这怎么可能呢?

代码语言:javascript
复制
CookieContainer = new CookieContainer();

//Create a WebRequest to get the file
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(@"http://www.example.com/file.zip);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-10 04:23:53

下面是一个使用CookieContainer的简单示例

代码语言:javascript
复制
       public static void Main(string[] args)
        {   
            if (args == null || args.Length != 1)
            {
                Console.WriteLine("Specify the URL to receive the request.");
                Environment.Exit(1);
            }
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]);
            request.CookieContainer = new CookieContainer();

            HttpWebResponse response = (HttpWebResponse) request.GetResponse();



            // Print the properties of each cookie.
            foreach (Cookie cook in response.Cookies)
            {                    
                // Show the string representation of the cookie.
                Console.WriteLine ("String: {0}", cook.ToString());
            }
        }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10964177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档