C # the following code example demonstrates how to end asynchronous operations to get the request stream, and then start a request to get the response .....

Source: Internet
Author: User
Private   Static   Void Endgetstreamcallback (iasyncresult AR)
{
Ftpstate state = (Ftpstate) Ar. asyncstate;

Stream requeststream =   Null ;
// End the asynchronous call to get the request stream.
Try
{
Requeststream = State. Request. endgetrequeststream (AR );
// Copy the file contents to the request stream.
Const   Int Bufferlength =   2048 ;
Byte [] Buffer =   New   Byte [Bufferlength];
Int Count =   0 ;
Int Readbytes =   0 ;
Filestream stream = File. openread (State. filename );
Do
{
Readbytes = Stream. Read (buffer, 0 , Bufferlength );
Requeststream. Write (buffer, 0 , Readbytes );
Count + = Readbytes;
}
While (Readbytes ! =   0 );
Console. writeline ( " Writing {0} bytes to the stream. " , Count );
// Important: Close the request stream before sending the request.
Requeststream. Close ();
// Asynchronously get the response to the upload request.
State. Request. begingetresponse (
New Asynccallback (endgetresponsecallback ),
State
);
}
// Return exceptions to the main application thread.
Catch (Exception E)
{
Console. writeline ( " Cocould not get the request stream. " );
State. operationexception = E;
State. operationcomplete. Set ();
Return ;
}

}

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.