c# - Login to web page using HttpWebRequest -


i trying login website below using httpwebrequest. passing in username , password using credentials property keep getting login page of website. can explain doing wrong.

https://oyster.tfl.gov.uk/oyster/entry.do (login page)

httpwebrequest request = (httpwebrequest)httpwebrequest.create(url); request.contenttype = "application/x-www-form-urlencoded";  request.credentials = new networkcredential(username, password); request.method = "post"; request.accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.headers.add("accept-language: en-us,en;q=0.5"); request.headers.add("accept-encoding: gzip,deflate"); request.headers.add("accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.7"); request.keepalive = true; request.headers.add("keep-alive: 300"); request.referer = url; request.useragent = "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; .net clr 1.0.3705;)";  httpwebresponse response = (httpwebresponse)request.getresponse();  using (streamreader reader = new streamreader(response.getresponsestream())) {     string tmp = reader.readtoend(); } 

note terms , conditions:

the following prohibited [...snip...]

use of automated system, software or process extract content and/or data, including trawling, data mining , screen scraping.

credentials basic/etc http security - not forms-based security.

it better use api if 1 exists. html forms meant humans, not computers. looks there beta tfl api here.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -