Misuse of httpwebrequest and server. Execute

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.