gpt4 book ai didi

c# - 无法将类型 'void' 隐式转换为 'System.Net.CookieContainer'

转载 作者:太空宇宙 更新时间:2023-11-03 20:00:48 33 4
gpt4 key购买 nike

<分区>

我只是想在我的网络请求中设置一个 cookie,但由于错误“无法将类型‘void’隐式转换为‘System.Net.CookieContainer’”而无法执行。

如果下面的代码不起作用 - 你如何实现它?

    public static string GET(string url, string cookieValue, string cookieName)
{
string response = "";
Uri target = new Uri(url);
var host = target.Host;
Cookie c = new Cookie(cookieValue, cookieName) { Domain = host };
CookieContainer cookieContainer = new CookieContainer().Add(c);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
request.Method = "GET";
request.CookieContainer = cookieContainer;
WebResponse response1 = request.GetResponse();
Stream dataStream = response1.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);

response = reader.ReadToEnd();

reader.Close();
response1.Close();
return response;
}

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