0

I am submitting a aspx with my C# code behind which works good, however I get the html direct back as I do not display this in a browser.

This is my C# code:

  string getUrl = "https://www.facebook.com/login.php?login_attempt=1";
  string email = "email@email.com";
  string pw = "pwd";
  string postData = String.Format("email={0}&pass={1}", email, pw);
  HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
  getRequest.CookieContainer = new CookieContainer();
  getRequest.CookieContainer.Add(cookies); //recover cookies First request
  getRequest.Method = WebRequestMethods.Http.Post;
  getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
  getRequest.AllowWriteStreamBuffering = true;
  getRequest.ProtocolVersion = HttpVersion.Version11;
  getRequest.AllowAutoRedirect = true;
  getRequest.ContentType = "application/x-www-form-urlencoded";

  byte[] byteArray = Encoding.ASCII.GetBytes(postData);
  getRequest.ContentLength = byteArray.Length;
  Stream newStream = getRequest.GetRequestStream(); //open connection
  newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
  newStream.Close();
  HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
         string sourceCode = "";
         using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
         {
             sourceCode = sr.ReadToEnd();
         }

this delivers me the response I need, however the page should load javascript first and than delivered back as html, unfortunatly it does not do this.

I have been looking to:

  1. Open this page on POST in a popup browser (or at least post this and wait till javascript is loaded complete)
  2. Get the loaded page back after javascript is fully loaded instead of the current

Of course I prefer this to be before:

 HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();

I have tried to: - use WebBrowser wb = new WebBrowser();, however this gives a single thread error and seems not to be possible to Post the page to the url. - while (wb.ReadyState != WebBrowserReadyState.Complete), this can't be used as I do not load a actually page but get only the response

Anybody has a good and smart idea to load the page in a browser with the POST, wait till javascript has been executed and me load this html into my C# code?

Sven Grosen
  • 5,616
  • 3
  • 30
  • 52
Jaap Terlouw
  • 125
  • 1
  • 15
  • Could you elaborate on your last paragraph? – shay__ Jun 23 '14 at 17:10
  • I need to use the POST to load the return fully, as now I get the html back direct without loaded javascript functions. – Jaap Terlouw Jun 23 '14 at 17:17
  • What do you mean by 'get the html back direct' and 'loaded javascript function' ? – shay__ Jun 23 '14 at 17:27
  • The POST it to the current code logs in and returns the main page from facebook, however the mainpage from facebook is being returned direct without loading the javascript functions (which is logic from my point of view as I do not load it in a browser but only to the server) so I need to make sure with the post it loads in a browser direct under the facebook account and get this response after its being loaded back. The page is full of javascript functions and being removed after all being loaded from the html. If you give me your email address can send it to you... – Jaap Terlouw Jun 23 '14 at 17:31
  • You can run this code and read out the "sourceCode", this piece of html I don't want I need the html after the javascript function have been runned. – Jaap Terlouw Jun 23 '14 at 17:49

0 Answers0