zoukankan      html  css  js  c++  java
  • C# 下面的代码示例演示如何结束异步操作以获取请求的流,然后开始一个请求以获取响应。....

    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(
    "Could not get the request stream.");
            state.OperationException 
    = e;
            state.OperationComplete.Set();
            
    return;
        }

    }
  • 相关阅读:
    称重量
    计算机网络
    进程间的通信方式与区别
    求两IP是否在同一局域网(运子网掩码用)
    Linux Redhat7 磁盘阵列基本原理
    Linux Redhat7更改root用户密码
    更改Linuxshell类型
    linux系统下的/var/spool/mail/root
    centos 解决"不在 sudoers 文件中。此事将被报告
    redhat 7 安装图形界面
  • 原文地址:https://www.cnblogs.com/Fooo/p/1325354.html
Copyright © 2011-2022 走看看