Using httpwebrequest to get response and setting headers properly c# -
i trying httpwebresponse of webpage http://www.reuters.com/finance/stocks/financialhighlights?symbol=nok wanting set httpwebrequest headers receive correct response when use firebug can see request financialhighlights?symbol=nok
request headers accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-encoding gzip, deflate accept-language en-us,en;q=0.5 cache-control max-age=0 connection keep-alive cookie info=edition=us; autorefresh=true; __csmv=8217fe64d605ff53; tns=datasource=cookie&value=r%3awmt.n%2cr%3anok%2cr%3amxwl.o%2cr%3aznga.o%2cr%3acl%2cr%3agway.n%2cr%3awac; _tr_id.6e08dd17=a90fa05e29dee8e5.1372892223.15.1375294449.1375242766; rsi_segs=i07714_10493|i07714_10507|i07714_10383|i07714_10162|i07714_10173|i07714_10267|i07714_10272|i07714_10445|i07714_10484|i07714_10246|i07714_10495|i07714_10502|i07714_10077|i07714_10379|i07714_10381|i07714_10539|i07714_10540|i07714_0; wt_fpc=id=173.18.210.14-448669392.30308073:lv=1375312449650:ss=1375306512018; __utma=108768797.1221077780.1375239985.1375239985.1375288512.2; __utmz=108768797.1375239985.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _lsd0=d00be99d-db81-4118-ad9d-4979ac859ed7; __csv=52ebad372f495912|0; __qca=p0-1654114799-1372892258182; burt_test=1; richuserid=mqj3uh6pvzdx; __csgeo=deg.16153_deg5.674_deg10.175_cc.us; __csnv=7c7a6d0ce0740439; cto_reuters=; _tr_ses.6e08dd17=1375288511678; _tr_cv.6e08dd17=false; __utmb=108768797.25.10.1375288512; __ctl=52ebad372f4959121; info=edition=us; __utmc=108768797; richsync=%7b%22burt%22%3a%22mqtbou2r7gkv%22%7d; __csref=http%3a%2f%2fwww.reuters.com%2ffinance%2fstocks%2foverview%3fsymbol%3dnok; __cst=74e4787bfc3bc90f host www.reuters.com referer http://www.reuters.com/finance/stocks/financialhighlights?symbol=nok user-agent mozilla/5.0 (windows nt 6.1; wow64; rv:22.0) gecko/20100101 firefox/22.0
and
response headers connection keep-alive content-length 78734 content-type text/html;charset=utf-8 date wed, 31 jul 2013 18:19:25 gmt expires wed, 31 jul 2013 18:09:51 gmt server apache vary accept-encoding
this reponse getting , response showing in firebug not same
this cs file using using system; using system.text; using system.net; using system.web; using system.io;
static class main { static void main(string[] args) { httpwebrequest hwr = (httpwebrequest)webrequest.create("http://www.reuters.com/finance/stocks/financialhighlights?symbol=nok"); hwr.method = "get"; hwr.cookiecontainer = new cookiecontainer(); //hwr.cookiecontainer = persistentcookies.getcookiecontainerforurl(url); hwr.accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; hwr.headers.add(httprequestheader.acceptencoding, "gzip, deflate"); hwr.headers.add(httprequestheader.acceptlanguage, "en-us,en;q=0.5"); string x = "info=edition=us; autorefresh=true; __csmv=8217fe64d605ff53; tns=datasource=cookie&value=r%3awmt.n%2cr%3anok%2cr%3amxwl.o%2cr%3aznga.o%2cr%3"; x += "acl%2cr%3agway.n%2cr%3awac; _tr_id.6e08dd17=a90fa05e29dee8e5.1372892223.15.1375290575.1375242766; rsi_segs=i07714_10383|i07714_10173|i07714_10267|"; x += "i07714_10272|i07714_10445|i07714_10484|i07714_10379|i07714_10381|i07714_10540|i07714_0; wt_fpc=id=173.18.210.14-448669392.30308073:lv=1375308577125:"; x += "ss=1375306512018; __utma=108768797.1221077780.1375239985.1375239985.1375288512.2; __utmz=108768797.1375239985.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd"; x += "(none); _lsd0=d00be99d-db81-4118-ad9d-4979ac859ed7; __csv=52ebad372f495912|0; __qca=p0-1654114799-1372892258182; burt_test=1; richuserid=mqj3uh6pvzdx;"; x += " __csgeo=deg.16153_deg5.674_deg10.175_cc.us; __csnv=987c0e966f13095; cto_reuters=; info=edition=us; _tr_ses.6e08dd17=1375288511678; _tr_cv.6e08dd17=false;"; x += " __utmb=108768797.11.10.1375288512; __utmc=108768797; __csref=http%3a%2f%2fwww.reuters.com%2ffinance%2fstocks%2foverview%3fsymbol%3dnok; __cst=19b4dea64115"; x += "8295; __ctl=52ebad372f4959121"; hwr.headers.add(httprequestheader.cookie, x); hwr.keepalive = true; hwr.host = "www.reuters.com"; hwr.referer = "http://www.reuters.com/finance/stocks/financialhighlights?symbol=nok"; hwr.useragent = "mozilla/4.0 (compatible; msie 6.0; windows nt 5.2; .net clr 1.0.3705;)"; httpwebresponse response = (httpwebresponse)hwr.getresponse(); stream receivestream = response.getresponsestream(); encoding encode = system.text.encoding.getencoding("utf-8"); streamreader readstream = new streamreader(receivestream, encode); string linesofhtml = readstream.readtoend(); system.console.writeline(linesofhtml); system.console.readkey(); receivestream.close(); response.close(); readstream.close(); } }
the httpwebreponse not same html want get, how set headers recieve correct reponse;
the reponse getting html source www.reuters.com/finance/stocks/overview?symbol=nok
but want source www.reuters.com/finance/stocks/financialhighlights?symbol=nok
Comments
Post a Comment