Making Http Call from c# -
there classic asp application makes calls .shtml files using asphttp.conn. makes request appending input , reads response reading values in response length. here example
strmessage= "test.shtml" set httpobj = server.createobject("asphttp.conn") httpobj.url = url & strmessage httpobj.postdata = "testarea=" & strrequestdata httpobj.timeout = 60 httpobj.requestmethod = "post" strresponsedata = httpobj.geturl response.write mid(strresponsedata,3,1) response.write mid(strresponsedata,4,3)
if need rewrite this, best way this. using mvc , rewriting ui. best approach make httpcall c#?. backend request sent not changed. please suggest.
using .net framework 4.5 can make request as
public static async task<int> htmlloadasync(string url/*, bool adduseragent = false*/) { try { var client = new httpclient(); //if (adduseragent) optional //{ // client.defaultrequestheaders.useragent.parseadd(useragent); //} //client.timeout = timeout; var response = client.getstringasync(url); //here can change client method according required outpu var urlcontents = await response; // process urlcontents } catch (exception ex) { console.writeline(ex.message); } return 0; }
now call as
private async void process() { await htmlloadasync("http://...."); }
note: must have add reference system.net.http
Comments
Post a Comment