submits and accepts data streams

Source: Internet
Author: User
Tags string back


Submit page:


Public partial class default2: system. Web. UI. Page
Protected void page_load (Object sender, eventargs E)


Public String webrequest (string URL, byte [] BYT)
Httpwebrequest web = (httpwebrequest) webrequest. Create (URL );
Web. method = "Post ";
Web. contentlength = BYT. length;
Stream STR = web. getrequeststream ();
Str. Write (BYT, 0, byt. Length );
Str. Close ();

// Accept the response
Httpwebresponse webresp = (httpwebresponse) web. getresponse ();
Stream STRM = webresp. getresponsestream ();
Streamreader sr = new streamreader (STRM, encoding. Default );
String MSG = Sr. readtoend ();
Sr. Close ();
Webresp. Close ();

Return MSG;
Protected void button#click (Object sender, eventargs E)
String url = string. Format ("http: // localhost: 52435/website1/default3.aspx? Id = {0} ", 10 );
// Read the file
String filepath = server. mappath (@ "201005121757351752.xls ");
Filestream = new filestream (filepath, filemode. Open, fileaccess. Read );
Byte [] BYT = new byte [filestream. Length];
Filestream. Read (BYT, 0, byt. Length );
Filestream. Close ();
Filestream. Dispose ();
// Output return value
String back = webrequest (URL, BYT );
Response. Write (back );



Acceptance page:


Public partial class default3: system. Web. UI. Page
Protected void page_load (Object sender, eventargs E)
// Accept parameters
String id = convert. tostring (request ["ID"]);
If (ID = NULL)
Response. Write ("object is null ");
// Accept the data stream to create a file
Stream stream = request. inputstream;
Byte [] BYT = new byte [stream. Length];
Stream. Read (BYT, 0, byt. Length );
String createnewfile = server. mappath (@ "aa.xls ");
File. writeallbytes (createnewfile, BYT );
Response. Write ("create successful! ");



Related Article

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: 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.