gpt4 book ai didi

c# - 如何将 CookieCollection 插入到 CookieContainer 中?

转载 作者:IT王子 更新时间:2023-10-29 04:53:58 27 4
gpt4 key购买 nike

在我收到 httpwebrequest 的响应后,我希望将获取的 cookie 保存起来,以便在另一个 httbwebrequest 中使用它们。但是,我需要将 CookieCollection 插入到 CookieContainer。我怎么做?尝试做:

request.Cookiecontainer.add(response.Cookies);

但是这样一直报错:Object reference not set to an instance of an object.

最佳答案

request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(response.Cookies);

根据微软的说法:

CookieContainer is a null reference (Nothing in Visual Basic) by default. You must assign a CookieContainer object to the property to have cookies returned in the Cookies property of the HttpWebResponse returned by the GetResponse method.

关于c# - 如何将 CookieCollection 插入到 CookieContainer 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/546369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com