title: Logging into a website via C#, navigating to another web page, and then output the source code as a string
body: <p>I am relatively new to working with web pages in C#. What I am trying to do is log into a particular website ( <a href="https://www15.swalife.com/PortalWeb/portal/cwaLogon.jsp">https://www15.swalife.com/PortalWeb/portal/cwaLogon.jsp</a> ) and allowing the page to be redirected to the default page, and then navigating from there to (https://www15.swalife.com/csswa/ea/plt/accessELITT.do) and downloading the source code and output it to a string.</p>
  
  <p>I have figured out how to download the source code via HTTPWebRequest and HTTPWebResponse but am having trouble on coding the logging in function. I assume I will have to do something with  POST? I have looked at <a href="http://www.dreamincode.net/forums/topic/152297-c%23-log-in-to-website-programmatically/">http://www.dreamincode.net/forums/topic/152297-c%23-log-in-to-website-programmatically/</a> also.</p>
  
  <h2>Thanks in advance!!</h2>
  
  <h2>EDIT:</h2>
  
  <p>The code supplied by jimmyjambles works flawlessly, except it doesn't quite get me the source code of the page I wanted. The code suggests that the log-in process failed, but I believe with a little bit of tweaking I could get it to work...also to everyone having issues with:</p>
  
  <pre><code>ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
  </code></pre>
  
  <p>Try changing your "public string" and "public bool" functions to "public static string" and "public static bool" respectively :)</p>
  
  <h2>EDIT 2:</h2>
  
  <p>Response HTML:</p>
  
  <pre><code>"&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"&gt;\n&lt;HTML&gt;\n&lt;HEAD&gt;\n\n\n\n\n\n\n&lt;META http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"&gt;\n&lt;META name=\"GENERATOR\" content=\"IBM WebSphere Studio\"&gt;\n&lt;TITLE&gt;endSession.jsp&lt;/TITLE&gt;\n&lt;LINK rel=\"stylesheet\" href=\"eipPortletStyles/swalife.css\" type=\"text/css\"&gt;\n\t&lt;script type=\"text/javascript\" language=\"JavaScript\" \n\t\tsrc=\"eipCommonJavaScript/eipGeneralFunctions.js\"/&gt; &lt;/script&gt;\n\t\t\n&lt;script type=\"text/javascript\"&gt;\n\n\tfunction refreshParent()\n\t{\n\t    if(window.parent)\n\t    {\n\t    if(window.parent.name == 'appMainFrame')\n\t       window.parent.location = \"/csswa/ea/plt/logout.do\";\n\t    //  alert('Your session has expired.  Please login again. ');\n\t    }\n\t}\n\n&lt;/script&gt;\n&lt;/HEAD&gt;\n&lt;BODY onload=\"refreshParent();\"&gt;\n \n\t \t&lt;div class=\"eipErrors\"&gt;\n  \t\t\t&lt;div class=\"legendLabel\"&gt;Message&lt;/div&gt;\n  \t\t\t\n  \t\t\t    &lt;div class=\"errorsHeader formTitle\"&gt;You Have Exited Out of Crew Web Access.&lt;br&gt;  \t\t\t \n  \t\t\t    &lt;/div&gt;\n  \t\t\t \n  \t\t\t&lt;div class=\"errorsHeader formTitle\"&gt; Please Close this Window and &lt;font  size=\"+1\"&gt;Log Out of SWALife&lt;/font&gt; to Complete the Log Out Process.  &lt;/div&gt;\n  \t\t&lt;div class=\"errorsText\"&gt;\n  \t\t  &amp;nbsp;\n  \t\t\t\t\n  \t\t&lt;/div&gt;\n  \t\t\n  \t\t\t\n  \t\t\n  \t\t&lt;div class=\"errorsFooter\"&gt;You will need to log back in before continuing.&lt;/div&gt;  \t\n  \t\t\n \t&lt;/div&gt;\n  \n&lt;/BODY&gt;\n&lt;/HTML&gt;\n"
  </code></pre>