c# - Window 8 retrieve HTML content -


here simple function retrive html content website. people can extract data it. found window 8 have http webservice html. , found way only. if anyonehave better way please share.

 protected  override void onnavigatedto(navigationeventargs e)             {                  gethtml("url");             }              public async void gethtml(string url)             {                 httpwebrequest myrequest = (httpwebrequest)webrequest.create(url);                 webresponse myresponse = await myrequest.getresponseasync();                 streamreader sr = new streamreader(myresponse.getresponsestream(), system.text.encoding.utf8);                 maintxtbox.text = sr.readtoend();               } 

since window 8 httpwebrequest have "getresponseasync" have use await. , away in async function. async function return task<> or void. , after change task<> other format confuse , messy. make return void , transfer data other global source. dont find simple explaination how string task. use way.

your gethtml should return task not void. async event handlers may safely return void.

protected async override void onnavigatedto(navigationeventargs e) {     await gethtml("url"); }  public async task gethtml(string url) {     httpwebrequest myrequest = (httpwebrequest)webrequest.create(url);     webresponse myresponse = await myrequest.getresponseasync();     streamreader sr = new streamreader(myresponse.getresponsestream(), system.text.encoding.utf8);     maintxtbox.text = sr.readtoend();   } 

however, put this:

protected async override void onnavigatedto(navigationeventargs e) {     maintxtbox.text = await gethtml("url"); }  public async task<string> gethtml(string url) {     httpwebrequest myrequest = (httpwebrequest)webrequest.create(url);     webresponse myresponse = await myrequest.getresponseasync();     streamreader sr = new streamreader(myresponse.getresponsestream(), system.text.encoding.utf8);     return sr.readtoend();   } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -