내가 .NET 3.5에서 실행하려고 할 때 다음 코드는 응답 (I 4 .NET으로 프로젝트를 설정할 때 작동) (I 2 분처럼 기다렸다 - 그것은 동결 것)HttpWebRequest.GetResponse은() .NET 3.5에 달려 있지만 .NET에서 작동 4
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 사이의 변화를 찾을 수 없습니다. 누구든지 그런 문제에 부딪 혔습니까?
'l_sHost'의 형식이 잘못되었습니다 - "* https :/* website.com"은 "* https : //*website.com"이어야합니다. 그것이 코드에 포함되어 있는지, 아니면 질문에 오타가 있는지 확실하지 않습니다. –
수정 됨. 감사! – Nitay