c# - .NET HTTP POST Method - Cookies AirFrames.org -
trying use c# post httpwebrequest airframes.org aircraft information. code use many other post request no problems (used other urls), / not able load airframes.org page using icao24 number (a64294).
var cookies = new cookiecontainer(); servicepointmanager.expect100continue = false; var request = (httpwebrequest)webrequest.create("http://www.airframes.org/"); request.cookiecontainer = cookies; request.method = "post"; request.keepalive = true; request.contenttype = "application/x-www-form-urlencoded"; using (var requeststream = request.getrequeststream()) using (var writer = new streamwriter(requeststream)) { writer.write("reg=&selcal=&icao24=a64294&submit=submit"); } using (var responsestream = request.getresponse().getresponsestream()) using (var reader = new streamreader(responsestream)) { var result = reader.readtoend(); console.writeline(result); }
note site has no-bots policy, why request won't work.
that being said, if still wish request page, adding user-agent string (so request looks came browser) trick:
request.useragent = "mozilla/6.0 (windows nt 6.2; wow64; rv:16.0.1) gecko/20121011 firefox/16.0.1"; it idea respect policies of site. code above merely educational purposes.
Comments
Post a Comment