Authentication and POST with C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JennyV
    New Member
    • Jan 2009
    • 3

    Authentication and POST with C#

    Hello,

    I have been searching the internet about methods for a C# console program to login and post on a website.

    I have been advised to either make the program log in every time when is necessary or to somehow include the session cookies with which I am logged in with my browser.


    I am afraid though that some of the methods don't work with every website and specifically with those I need like playrohan.com

    This is the login page that I have already got past with my browser but in order the program to authenticate I think it needs the cookies or to login itself

    And the string I need to be posted is a known password string of 6 characters in the field "userpwd" or any of the link accessed from this page

    Can anyone who has experience in this please give me a hint of what works with such kind of sites and with this one particularly and suggest what functions I should use? And any guidance of the best method to proceed is much appreciated.

    Sincerely,
    Jenny
    Last edited by Frinavale; Feb 11 '09, 02:51 PM. Reason: removed links as requested
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You need to look into using HttpWebRequest Object to make a request to the web page.


    Please note that forms authentication uses authentication and session cookies to work. If these are missing then you cannot provide the login credentials to the page after the user has logged in. You need to capture the cookies issued by the page. You should look into how to use the CookieContainer to capture cookies.

    Comment

    • JennyV
      New Member
      • Jan 2009
      • 3

      #3
      Yes thanks i used HttpWebRequest and HttpWebResponse to get the cookie as a string and then applying that cookie with Headers.Add for the POST request to work from my name.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I'm glad you got this working :)

        Comment

        Working...