private CookieContainer GetCookies()
{
CookieContainer myCookieContainer = new CookieContainer();
HttpCookie requestCookie;
int requestCookiesCount = Request.Cookies.Count;
for (int i = 0; i < requestCookiesCount; i++)
{
requestCookie = Request.Cookies[i];
Cookie clientCookie = new Cookie(requestCookie.Name, requestCookie.Value, requestCookie.Path, requestCookie.Domain == null ? Request.Url.Host : requestCookie.Domain);
myCookieContainer.Add(clientCookie);
}
return myCookieContainer;
}
private string CallPage(string url)
{
WebResponse response = null;
Stream stream = null;
StreamReader reader = null;
try
{
CookieContainer myCookieContainer = GetCookies();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "Get";
request.CookieContainer = myCookieContainer;
response = request.GetResponse();
if (!request.HaveResponse)
{
response.Close();
return string.Empty;
}
stream = response.GetResponseStream();
reader = new StreamReader(stream, Encoding.Default);
return reader.ReadToEnd();
}
catch (Exception exception)
{
var handled = ExceptionManager.HandleException(exception, "Global");
throw exception;//TODO
}
finally
{
if (reader != null) reader.Close();
if (stream != null) stream.Close();
if (response != null) response.Close();
}
}