Original Post
I'm pretty sure I know what a StackOverflowException is, I've seen it happen when I put big numbers in a recursive program, but I don't see how it's happening here. It occurs when I call the method Request, around where the comment indicates.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
public class Interweb
{
public CookieCollection Cookies
{
get
{
return Cookies;
}
set
{
Cookies = value;
}
}
public Interweb()
{
}
public String Request(String Method, String URL, String Post, String Referer)
{
HttpWebRequest http = (HttpWebRequest)WebRequest.Create(URL);
http.Timeout = 10000;
http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
http.Referer = Referer;
http.CookieContainer = new CookieContainer();
Console.WriteLine("Check");
if (Cookies != null && Cookies.Count > 0) //StackOverflowException happens hereish
{
http.CookieContainer.Add(Cookies);
}
Console.WriteLine("Check");
if (Method == "POST")
{
http.Method = "POST";
byte[] postBuffer = Encoding.GetEncoding(1252).GetBytes(Post);
http.ContentLength = postBuffer.Length;
Stream sendPost = http.GetRequestStream();
sendPost.Write(postBuffer, 0, postBuffer.Length);
sendPost.Close();
}
HttpWebResponse response = (HttpWebResponse)http.GetResponse();
if (response.Cookies.Count > 0)
{
if (Cookies == null)
{
Cookies = response.Cookies;
}
else
{
foreach (Cookie respCookies in response.Cookies)
{
bool match = false;
foreach (Cookie currentCookies in Cookies)
{
if (respCookies.Name == currentCookies.Name)
{
currentCookies.Value = respCookies.Value;
match = true;
break;
}
}
if (!match)
{
Cookies.Add(respCookies);
}
}
}
}
Encoding enc = Encoding.GetEncoding(1252);
StreamReader respStream = new StreamReader(response.GetResponseStream(), enc);
String html = respStream.ReadToEnd();
return html;
}
}