Using WebClient or WebRequest to login to a website and access data

前端 未结 2 1409
一向
一向 2020-11-28 07:27

I\'m trying to access restricted data on a website using WebClient/WebRequest. There is no official API in that website, so what I\'m trying to do

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 08:06

    HTTP is stateless. So, you cannot WebClient permanently logged in. The concept of a session does not exist in HTTP. The server-side technologies such as ASP.NET simulate a stateful behavior through the concept of session using cookie or a query string parameter that gets sent back and forth in every request. Having said that, it is possible to emulate what a browser does from WebClient. If you have access to the website, connect to it using the right credentials and capture the traffic using Fiddler. Then, make sure WebClient sends out the right cookies, request headers, query strings, etc exactly same as the browser.

提交回复
热议问题