I am trying to open a new thread from my default.aspx, however I get the error: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
Getting this with this code:
WebBrowser wb = new WebBrowser();
protected void Page_Load(object sender, EventArgs e)
{
string urlAddress = "https://www.facebook.com/login.php?login_attempt=1";
string email = "";
string pw = "";
string PostData = String.Format("email={0}&pass={1}", email, pw);
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(urlAddress);
req.CookieContainer = cookieContainer;
req.Method = "POST";
req.ContentLength = PostData.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.AllowAutoRedirect = true;
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginDataBytes = encoding.GetBytes(PostData);
req.ContentLength = loginDataBytes.Length;
Stream stream = req.GetRequestStream();
stream.Write(loginDataBytes, 0, loginDataBytes.Length);
HttpWebResponse webResp = (HttpWebResponse)req.GetResponse();
Stream datastream = webResp.GetResponseStream();
StreamReader reader = new StreamReader(datastream);
string data = reader.ReadToEnd();
wb.DocumentText = reader.ReadToEnd();
}
The error I get already with calling the first line.
With a little research on internet I found dozen of subjects on this however I am not able to put this in a single thread till now, so I can open a browser and get the response back from this one.
Anybody any good suggestion?