How to login to HTML form using POST vars in C# (.NET)?

后端 未结 3 655
深忆病人
深忆病人 2021-01-15 02:34

For example, there is this website: www.azet.sk

On the right, there is login and password, I\'d like my application to login to this web application and retrieve the

3条回答
  •  清酒与你
    2021-01-15 03:10

    The login part should be relatively easy.

    Use System.Net.WebClient and the UploadValues() method to POST the form data. Look at the HTML source to figure out the field values to POST.

    Most forms-based auth mechanisms use an HTTP cookie to keep the user logged in. So, after you POST the values, examine the WebClient's ResponseHeaders collection for the 'Set-Cookie:' header.

    Store the cookie value for subsequent GETs/POSTs to the website.

    You'll probably find that "retrieving the data from your account and working with it" is much more complicated (i.e. screen-scraping, etc).

    Here's a link that has some examples:

    http://codebetter.com/blogs/brendan.tompkins/archive/2005/05/18/63329.aspx

提交回复
热议问题