1

I'm trying to use C# to login to a website, and then go to other pages of the website(that require being logged in) and get the HTML so I can parse with htmlagilitypack.

I can get the html of a webpage no problem, but I'm having difficulty with the logging in part.

I started up Fiddler and logged in to see what would come up(I am new to fiddler) and two things come up on the list, both CONNECT (i was expecting it would be a post since the form is POST???)

The website I am trying to get into is: https://amn.efanniemae.com/AMN/control

Can anyone point me in the right direction / show me how to do this?

Thank you.

Kyle
  • 32,731
  • 39
  • 134
  • 184

2 Answers2

1

You may want to check with the owners of the site or the documentation to see if they have any automated methods of logging in. Some login systems support automated loggins by allowing you to send information in query string (very insecure) or will provide you with the proper POST values to send. Note that an automated POST login may be different than a manual login (ie: set a hidden form value to AutoLogin, etc.) and some sites will not want people automating the login process for security purposes.

If you succeed with the first step, most sites will send you a cookie with information about your session. So to keep your session between requests you simply have to save this cookie, then send it with the next request. With the HttpWebRequest object you can use the CookieContainer property to obtain the cookie.

For more details about saving the cookie, see this SO post, How do I log into a site with WebClient?

Community
  • 1
  • 1
Despertar
  • 21,627
  • 11
  • 81
  • 79
1

Fiddler won't decrypt the ssl traffic until you enable it in Options. Go to Fiddler Options, check "decrypt ssl traffic", trust the certificate and you will see the traffic.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106