I have a webpage that needs to apply for data directly from another webpage in Code . Therefore, I found a piece of code to implement it, which is implemented using httpwebrequest. As for the principle or process, I didn't understand it at all:
string Surl = system. web. httpcontext. current. request. URL. tostring ();
Surl = Surl. substring (0, Surl. lastindexof ("/") + 1);
httpwebrequest HWR = (httpwebrequest) webrequest. create (
Surl + "Cx. ashx? Qttj = "+ request. querystring ["qttj"]);
HWR. method = "get";
HWR. sendchunked = false;
webresponse wR = HWR. getresponse ();
system. io. stream NS = Wr. getresponsestream ();
long l = Wr. contentlength;
byte [] B = new byte [l];
for (INT I = 0; I {< br> B [I] = (byte) ns. readbyte ();
}< br> ns. close ();
Wr. close ();
divcont. innerhtml = system. text. encoding. utf8.getstring (B);
the web page to be called will use session again later. After finding a lot of information, we can see that httpwebrequest is actually used to apply for data from other websites, instead of applying for data from several webpages in a project.
now we can find the server. Execute method to replace it. After running the command, we can see that the speed is much faster.
system. Io. stringwriter Sw = new stringwriter ();
server. Execute ("Cx. ashx? Qttj = "+ request. querystring ["qttj"], SW); . an error occurred while executing the subrequest in ashx, but it is okay to call Aspx.)
string shtml = Sw. tostring ();
divcont. innerhtml = shtml;
if you do not have a preliminary understanding of these technologies, you can stick the Code provided by others to produce results. We didn't plan the classification and Tiering these things.