gpt4 book ai didi

asp.net - HttpWebRequest.GetResponse() 在 .NET 3.5 上挂起但在 .NET 4 上工作

转载 作者:行者123 更新时间:2023-12-04 03:04:08 25 4
gpt4 key购买 nike

以下代码在我尝试在 .NET 3.5 上运行时挂起(当我将项目设置为 .NET 4 时它有效)

(我已经等了大约 2 分钟 - 它似乎卡住了)

        HttpWebRequest l_oRequest;
HttpWebResponse l_oResponse;

if (m_bLoggedIn)
return true;

m_oSession = new SSessionIdentifier();
m_oSession.Cookies = new CookieContainer();

string l_sHost = "https://website.com";

// Start the login sequence
l_oRequest = GetNewRequest(l_sHost, "Login.aspx", m_oSession.Cookies);
l_oRequest.Timeout = 5000;
l_oRequest.ReadWriteTimeout = 5000;
l_oRequest.Method = "POST";
l_oRequest.Referer = "https://website.com";

// Set form parameters
string l_sFormParameters = "user=" + m_sUsername;

// Convert them to the HTTP stream
byte[] l_oRequestBuffer = UTF8Encoding.ASCII.GetBytes(l_sFormParameters);
var l_oRequestStream = l_oRequest.GetRequestStream();
l_oRequestStream.Write(l_oRequestBuffer, 0, l_oRequestBuffer.Length);

// I'm setting this to false because otherwise i can't get the cookies i want. And I love them cookies!
l_oRequest.AllowAutoRedirect = false;

// Now start the redirection sequence until we get to what we want
int l_iDTPos = -1;
// This line hangs
l_oResponse = (HttpWebResponse)l_oRequest.GetResponse();
while (l_oResponse.StatusCode == HttpStatusCode.Found)
{
// Yada Yada

这是 GetNewRequest 函数:

    private HttpWebRequest GetNewRequest(string host, string targetUrl, CookieContainer a_oCookieJar)
{
HttpWebRequest l_oRequest = (HttpWebRequest)HttpWebRequest.Create(host + targetUrl);
l_oRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2";
l_oRequest.ContentType = "application/x-www-form-urlencoded";
l_oRequest.AllowAutoRedirect = false;
l_oRequest.CookieContainer = a_oCookieJar;

return l_oRequest;
}

我在文档中找不到 3.5 和 4 之间的任何变化。有人遇到过这样的问题吗?

最佳答案

我在使用 HttpWebRequest 调用 RESTful 服务时遇到了同样的问题,我的代码在 .Net 4+ 中运行良好,并卡在 .Net 3.5、3.0 中的 GetResponse() 行上。 2.0。我最终尝试了本文中的示例代码:

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

并让它在所有版本的 .Net 中工作。我猜我没有设置正确的东西或关闭资源,但对于其他遇到此问题的人,请尝试一下这篇文章。

关于asp.net - HttpWebRequest.GetResponse() 在 .NET 3.5 上挂起但在 .NET 4 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13120855/

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