FtpWebRequest 类

定义

实现文件传输协议 (FTP) 客户端。Implements a File Transfer Protocol (FTP) client.

public ref class FtpWebRequest sealed : System::Net::WebRequest
public sealed class FtpWebRequest : System.Net.WebRequest
type FtpWebRequest = class
    inherit WebRequest
Public NotInheritable Class FtpWebRequest
Inherits WebRequest
继承

示例

下面的代码示例演示如何从 FTP 服务器中删除文件。The following code example demonstrates deleting a file from an FTP server.

static bool DeleteFileOnServer( Uri^ serverUri )
{
   // The serverUri parameter should use the ftp:// scheme.
   // It contains the name of the server file that is to be deleted.
   // Example: ftp://contoso.com/someFile.txt.
   // 
   if ( serverUri->Scheme != Uri::UriSchemeFtp )
   {
      return false;
   }

   // Get the object used to communicate with the server.
   FtpWebRequest^ request = dynamic_cast<FtpWebRequest^>(WebRequest::Create( serverUri ));
   request->Method = WebRequestMethods::Ftp::DeleteFile;
   FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
   Console::WriteLine( "Delete status: {0}", response->StatusDescription );
   response->Close();
   return true;
}
public static bool DeleteFileOnServer(Uri serverUri)
{
    // The serverUri parameter should use the ftp:// scheme.
    // It contains the name of the server file that is to be deleted.
    // Example: ftp://contoso.com/someFile.txt.
    // 
    
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Get the object used to communicate with the server.
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
    request.Method = WebRequestMethods.Ftp.DeleteFile;
 
    FtpWebResponse response = (FtpWebResponse) request.GetResponse();
    Console.WriteLine("Delete status: {0}",response.StatusDescription);  
    response.Close();
    return true;
}

下面的代码示例演示如何使用WebClient类从 FTP 服务器下载文件。The following code example demonstrates downloading a file from an FTP server by using the WebClient class.

static bool DisplayFileFromServer( Uri^ serverUri )
{
   // The serverUri parameter should start with the ftp:// scheme.
   if ( serverUri->Scheme != Uri::UriSchemeFtp )
   {
      return false;
   }

   // Get the object used to communicate with the server.
   WebClient^ request = gcnew WebClient;

   // This example assumes the FTP site uses anonymous logon.
   request->Credentials = gcnew NetworkCredential( "anonymous","janeDoe@contoso.com" );
   try
   {
      array<Byte>^newFileData = request->DownloadData( serverUri->ToString() );
      String^ fileString = System::Text::Encoding::UTF8->GetString( newFileData );
      Console::WriteLine( fileString );
   }
   catch ( WebException^ e ) 
   {
      Console::WriteLine( e );
   }

   return true;
}
public static bool DisplayFileFromServer(Uri serverUri)
{
    // The serverUri parameter should start with the ftp:// scheme.
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Get the object used to communicate with the server.
    WebClient request = new WebClient();
    
    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
    try 
    {
        byte [] newFileData = request.DownloadData (serverUri.ToString());
        string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
        Console.WriteLine(fileString);
    }
    catch (WebException e)
    {
        Console.WriteLine(e.ToString());
    }
    return true;
}

下面的代码示例演示如何使用异步操作将文件上载到 FTP 服务器。The following code example demonstrates using asynchronous operations to upload a file to an FTP server.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Threading;
using namespace System::IO;

public ref class FtpState
{
private:
   ManualResetEvent^ wait;
   FtpWebRequest^ request;
   String^ fileName;
   Exception^ operationException;
   String^ status;

public:
   FtpState()
   {
      wait = gcnew ManualResetEvent( false );
   }

   property ManualResetEvent^ OperationComplete 
   {
      ManualResetEvent^ get()
      {
         return wait;
      }

   }

   property FtpWebRequest^ Request 
   {
      FtpWebRequest^ get()
      {
         return request;
      }

      void set( FtpWebRequest^ value )
      {
         request = value;
      }

   }

   property String^ FileName 
   {
      String^ get()
      {
         return fileName;
      }

      void set( String^ value )
      {
         fileName = value;
      }

   }

   property Exception^ OperationException 
   {
      Exception^ get()
      {
         return operationException;
      }

      void set( Exception^ value )
      {
         operationException = value;
      }

   }

   property String^ StatusDescription 
   {
      String^ get()
      {
         return status;
      }

      void set( String^ value )
      {
         status = value;
      }

   }
};

public ref class AsynchronousFtpUpLoader
{
public:

   // Command line arguments are two strings:
   // 1. The url that is the name of the file being uploaded to the server.
   // 2. The name of the file on the local machine.
   //
   static void Main()
   {
      array<String^>^args = Environment::GetCommandLineArgs();

      // Create a Uri instance with the specified URI string.
      // If the URI is not correctly formed, the Uri constructor
      // will throw an exception.
      ManualResetEvent^ waitObject;
      Uri^ target = gcnew Uri( args[ 1 ] );
      String^ fileName = args[ 2 ];
      FtpState^ state = gcnew FtpState;
      FtpWebRequest ^ request = dynamic_cast<FtpWebRequest^>(WebRequest::Create( target ));
      request->Method = WebRequestMethods::Ftp::UploadFile;

      // This example uses anonymous logon.
      // The request is anonymous by default; the credential does not have to be specified. 
      // The example specifies the credential only to
      // control how actions are logged on the server.
      request->Credentials = gcnew NetworkCredential( "anonymous","janeDoe@contoso.com" );

      // Store the request in the object that we pass into the
      // asynchronous operations.
      state->Request = request;
      state->FileName = fileName;

      // Get the event to wait on.
      waitObject = state->OperationComplete;

      // Asynchronously get the stream for the file contents.
      request->BeginGetRequestStream( gcnew AsyncCallback( EndGetStreamCallback ), state );

      // Block the current thread until all operations are complete.
      waitObject->WaitOne();

      // The operations either completed or threw an exception.
      if ( state->OperationException != nullptr )
      {
         throw state->OperationException;
      }
      else
      {
         Console::WriteLine( "The operation completed - {0}", state->StatusDescription );
      }
   }

private:
   static void EndGetStreamCallback( IAsyncResult^ ar )
   {
      FtpState^ state = dynamic_cast<FtpState^>(ar->AsyncState);
      Stream^ requestStream = nullptr;

      // 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;
         array<Byte>^buffer = gcnew array<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, bufferLength );
            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( gcnew 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;
      }
   }

   // The EndGetResponseCallback method  
   // completes a call to BeginGetResponse.
   static void EndGetResponseCallback( IAsyncResult^ ar )
   {
      FtpState^ state = dynamic_cast<FtpState^>(ar->AsyncState);
      FtpWebResponse ^ response = nullptr;
      try
      {
         response = dynamic_cast<FtpWebResponse^>(state->Request->EndGetResponse( ar ));
         response->Close();
         state->StatusDescription = response->StatusDescription;

         // Signal the main application thread that 
         // the operation is complete.
         state->OperationComplete->Set();
      }
      // Return exceptions to the main application thread.
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Error getting response." );
         state->OperationException = e;
         state->OperationComplete->Set();
      }
   }
};

int main()
{
   AsynchronousFtpUpLoader::Main();
}
using System;
using System.Net;
using System.Threading;

using System.IO;
namespace Examples.System.Net
{
    public class FtpState
    {
        private ManualResetEvent wait;
        private FtpWebRequest request;
        private string fileName;
        private Exception operationException = null;
        string status;
        
        public FtpState()
        {
            wait = new ManualResetEvent(false);
        }
        
        public ManualResetEvent OperationComplete
        {
            get {return wait;}
        }
        
        public FtpWebRequest Request
        {
            get {return request;}
            set {request = value;}
        }
        
        public string FileName
        {
            get {return fileName;}
            set {fileName = value;}
        }
        public Exception OperationException
        {
            get {return operationException;}
            set {operationException = value;}
        }
        public string StatusDescription
        {
            get {return status;}
            set {status = value;}
        }
    }
    public class AsynchronousFtpUpLoader
    {  
        // Command line arguments are two strings:
        // 1. The url that is the name of the file being uploaded to the server.
        // 2. The name of the file on the local machine.
        //
        public static void Main(string[] args)
        {
            // Create a Uri instance with the specified URI string.
            // If the URI is not correctly formed, the Uri constructor
            // will throw an exception.
            ManualResetEvent waitObject;
            
            Uri target = new Uri (args[0]);
            string fileName = args[1];
            FtpState state = new FtpState();
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
            request.Method = WebRequestMethods.Ftp.UploadFile;
            
            // This example uses anonymous logon.
            // The request is anonymous by default; the credential does not have to be specified. 
            // The example specifies the credential only to
            // control how actions are logged on the server.
            
            request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
            
            // Store the request in the object that we pass into the
            // asynchronous operations.
            state.Request = request;
            state.FileName = fileName;
            
            // Get the event to wait on.
            waitObject = state.OperationComplete;
            
            // Asynchronously get the stream for the file contents.
            request.BeginGetRequestStream(
                new AsyncCallback (EndGetStreamCallback), 
                state
            );
            
            // Block the current thread until all operations are complete.
            waitObject.WaitOne();
            
            // The operations either completed or threw an exception.
            if (state.OperationException != null)
            {
                throw state.OperationException;
            }
            else
            {
                Console.WriteLine("The operation completed - {0}", state.StatusDescription);
            }
        }
        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;
            }
           
        }
        
        // The EndGetResponseCallback method  
        // completes a call to BeginGetResponse.
        private static void EndGetResponseCallback(IAsyncResult ar)
        {
            FtpState state = (FtpState) ar.AsyncState;
            FtpWebResponse response = null;
            try 
            {
                response = (FtpWebResponse) state.Request.EndGetResponse(ar);
                response.Close();
                state.StatusDescription = response.StatusDescription;
                // Signal the main application thread that 
                // the operation is complete.
                state.OperationComplete.Set();
            }
            // Return exceptions to the main application thread.
            catch (Exception e)
            {
                Console.WriteLine ("Error getting response.");
                state.OperationException = e;
                state.OperationComplete.Set();
            }
        }
    }
}

注解

重要

不建议使用FtpWebRequest类进行新的开发。We don't recommend that you use the FtpWebRequest class for new development. 有关的详细信息和替代FtpWebRequest方法, 请参阅WebRequest 不应在 GitHub 上使用。For more information and alternatives to FtpWebRequest, see WebRequest shouldn't be used on GitHub.

若要获取的FtpWebRequest实例, 请Create使用方法。To obtain an instance of FtpWebRequest, use the Create method. 你还可以使用WebClient类从 FTP 服务器上传和下载信息。You can also use the WebClient class to upload and download information from an FTP server. 使用上述任一方法时, 如果指定使用 ftp 方案的网络资源 (例如"ftp://contoso.com" FtpWebRequest ), 类就能以编程方式与 ftp 服务器交互。Using either of these approaches, when you specify a network resource that uses the FTP scheme (for example, "ftp://contoso.com") the FtpWebRequest class provides the ability to programmatically interact with FTP servers.

该 URI 可以是相对路径或绝对 URI。The URI may be relative or absolute. 如果 uri 的形式"ftp://contoso.com/%2fpath"为 (% 2f 是转义的 "/"), 则 uri 为绝对 uri, 当前目录为。 /pathIf the URI is of the form "ftp://contoso.com/%2fpath" (%2f is an escaped '/'), then the URI is absolute, and the current directory is /path. 但是, 如果 URI 的形式"ftp://contoso.com/path"为, 则首先 .NET Framework 登录到 FTP 服务器 (使用Credentials属性设置的用户名和密码), 然后将当前目录设置为<UserLoginDirectory>/pathIf, however, the URI is of the form "ftp://contoso.com/path", first the .NET Framework logs into the FTP server (using the user name and password set by the Credentials property), then the current directory is set to <UserLoginDirectory>/path.

必须为服务器提供有效的用户名和密码, 否则服务器必须允许匿名登录。You must have a valid user name and password for the server or the server must allow anonymous logon. 您可以通过设置Credentials属性来指定用于连接到服务器的凭据, 也可以UserInfo在传递给该Create方法的 URI 部分中包含它们。You can specify the credentials used to connect to the server by setting the Credentials property or you can include them in the UserInfo portion of the URI passed to the Create method. 如果在 URI UserInfo中包含信息Credentials , 则使用指定的用户名和密码信息将属性设置为新的网络凭据。If you include UserInfo information in the URI, the Credentials property is set to a new network credential with the specified user name and password information.

注意

除非属性为true, 否则所有数据和命令 (包括你的用户名和密码信息) 都将以明文形式发送到服务器。 EnableSslUnless the EnableSsl property is true, all data and commands, including your user name and password information, are sent to the server in clear text. 监视网络流量的任何人都可以查看凭据并使用它们连接到服务器。Anyone monitoring network traffic can view your credentials and use them to connect to the server. 如果要连接到需要凭据的 FTP 服务器并支持安全套接字层 (SSL), 则应将设置EnableSsl为。 trueIf you are connecting to an FTP server that requires credentials and supports Secure Sockets Layer (SSL), you should set EnableSsl to true.

您必须WebPermission访问 FTP 资源; 否则SecurityException , 将引发异常。You must have WebPermission to access the FTP resource; otherwise, a SecurityException exception is thrown.

通过将Method属性设置为WebRequestMethods.Ftp结构中定义的值来指定要发送到服务器的 FTP 命令。Specify the FTP command to send to the server by setting the Method property to a value defined in the WebRequestMethods.Ftp structure. 若要传输文本数据, 请UseBinary将属性从其默认值true() false更改为。To transmit text data, change the UseBinary property from its default value (true) to false. 有关详细信息和限制, Method请参阅。For details and restrictions, see Method.

使用FtpWebRequest对象将文件上载到服务器时, 必须将文件内容写入通过GetRequestStream调用方法或BeginGetRequestStream其异步对应项 (和EndGetRequestStream方法) 获得的请求流。When using an FtpWebRequest object to upload a file to a server, you must write the file content to the request stream obtained by calling the GetRequestStream method or its asynchronous counterparts, the BeginGetRequestStream and EndGetRequestStream methods. 在发送请求之前, 必须写入流并关闭流。You must write to the stream and close the stream before sending the request.

通过调用GetResponse方法或其异步对应项BeginGetResponse 、和EndGetResponse方法将请求发送到服务器。Requests are sent to the server by calling the GetResponse method or its asynchronous counterparts, the BeginGetResponse and EndGetResponse methods. 当请求的操作完成时, FtpWebResponse将返回一个对象。When the requested operation completes, an FtpWebResponse object is returned. FtpWebResponse对象提供操作的状态以及从服务器下载的任何数据。The FtpWebResponse object provides the status of the operation and any data downloaded from the server.

您可以使用ReadWriteTimeout属性设置用于读取或写入服务器的超时值。You can set a time-out value for reading or writing to the server by using the ReadWriteTimeout property. 如果超过超时期限, 则调用方法会引发WebException , 并WebExceptionStatus将设置为TimeoutIf the time-out period is exceeded, the calling method throws a WebException with WebExceptionStatus set to Timeout.

从 FTP 服务器下载文件时, 如果命令成功, 则所请求文件的内容可用于响应对象的流中。When downloading a file from an FTP server, if the command was successful, the contents of the requested file are available in the response object's stream. 可以通过调用GetResponseStream方法访问此流。You can access this stream by calling the GetResponseStream method. 有关详细信息,请参阅 FtpWebResponseFor more information, see FtpWebResponse.

如果该Proxy属性是直接设置的, 或者是在配置文件中设置的, 则通过指定的代理建立与 FTP 服务器的通信。If the Proxy property is set, either directly or in a configuration file, communications with the FTP server are made through the specified proxy. 如果指定的代理是 HTTP 代理, 则仅DownloadFile支持、 ListDirectoryListDirectoryDetails命令。If the specified proxy is an HTTP proxy, only the DownloadFile, ListDirectory, and ListDirectoryDetails commands are supported.

仅缓存下载的二进制内容;也就是说, 使用DownloadFile命令UseBinary接收的内容, 其属性设置为trueOnly downloaded binary content is cached; that is, content received using the DownloadFile command with the UseBinary property set to true.

如果FtpWebRequest可能, 多个重复使用现有连接。Multiple FtpWebRequests reuse existing connections, if possible.

有关 FTP 协议的详细信息, 请参阅RFC 959:文件传输协议For more information about the FTP protocol, see RFC 959: File Transfer Protocol.

属性

AuthenticationLevel

获取或设置用于此请求的身份验证和模拟的级别。Gets or sets values indicating the level of authentication and impersonation used for this request.

(继承自 WebRequest)
CachePolicy

获取或设置此请求的缓存策略。Gets or sets the cache policy for this request.

(继承自 WebRequest)
ClientCertificates

获取用于建立到 FTP 服务器的加密连接的证书。Gets or sets the certificates used for establishing an encrypted connection to the FTP server.

ConnectionGroupName

获取或设置连接组的名称,该连接组包含用于发送当前请求的服务点。Gets or sets the name of the connection group that contains the service point used to send the current request.

ContentLength

获取或设置被 FtpWebRequest 类忽略的值。Gets or sets a value that is ignored by the FtpWebRequest class.

ContentOffset

获取或设置请求所下载的文件的字节偏移量。Gets or sets a byte offset into the file being downloaded by this request.

ContentType

总是引发 NotSupportedExceptionAlways throws a NotSupportedException.

CreatorInstance

当在子类中重写时,获取从 IWebRequestCreate 类派生的工厂对象,该类用于创建为生成对指定 URI 的请求而实例化的 WebRequestWhen overridden in a descendant class, gets the factory object derived from the IWebRequestCreate class used to create the WebRequest instantiated for making the request to the specified URI.

(继承自 WebRequest)
Credentials

获取或设置用于与 FTP 服务器通信的凭据。Gets or sets the credentials used to communicate with the FTP server.

DefaultCachePolicy

定义所有 FTP 请求的默认缓存策略。Defines the default cache policy for all FTP requests.

EnableSsl

获取或设置 Boolean,它指定是否使用 SSL 连接。Gets or sets a Boolean that specifies that an SSL connection should be used.

Headers

获取空 WebHeaderCollection 对象。Gets an empty WebHeaderCollection object.

ImpersonationLevel

获取或设置当前请求的模拟级别。Gets or sets the impersonation level for the current request.

(继承自 WebRequest)
KeepAlive

获取或设置一个 Boolean 值,该值指定在请求完成之后是否关闭到 FTP 服务器的控制连接。Gets or sets a Boolean value that specifies whether the control connection to the FTP server is closed after the request completes.

Method

获取或设置要发送到 FTP 服务器的命令。Gets or sets the command to send to the FTP server.

PreAuthenticate

总是引发 NotSupportedExceptionAlways throws a NotSupportedException.

Proxy

获取或设置用于与 FTP 服务器通信的代理。Gets or sets the proxy used to communicate with the FTP server.

ReadWriteTimeout

获取或设置写入或读取流时的超时。Gets or sets a time-out when reading from or writing to a stream.

RenameTo

获取或设置重命名文件的新名称。Gets or sets the new name of a file being renamed.

RequestUri

获取此实例所请求的 URI。Gets the URI requested by this instance.

ServicePoint

获取用于连接 FTP 服务器的 ServicePoint 对象。Gets the ServicePoint object used to connect to the FTP server.

Timeout

获取或设置等待请求的毫秒数。Gets or sets the number of milliseconds to wait for a request.

UseBinary

获取或设置一个 Boolean 值,该值指定文件传输的数据类型。Gets or sets a Boolean value that specifies the data type for file transfers.

UseDefaultCredentials

总是引发 NotSupportedExceptionAlways throws a NotSupportedException.

UsePassive

获取或设置客户端应用程序的数据传输过程的行为。Gets or sets the behavior of a client application's data transfer process.

方法

Abort()

终止异步 FTP 操作。Terminates an asynchronous FTP operation.

BeginGetRequestStream(AsyncCallback, Object)

开始以异步方式打开请求的内容流以便写入。Begins asynchronously opening a request's content stream for writing.

BeginGetResponse(AsyncCallback, Object)

开始以异步方式向 FTP 服务器发送请求并从 FTP 服务器接收响应。Begins sending a request and receiving a response from an FTP server asynchronously.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
EndGetRequestStream(IAsyncResult)

结束由 BeginGetRequestStream(AsyncCallback, Object) 启动的挂起的异步操作。Ends a pending asynchronous operation started with BeginGetRequestStream(AsyncCallback, Object).

EndGetResponse(IAsyncResult)

结束由 BeginGetResponse(AsyncCallback, Object) 启动的挂起的异步操作。Ends a pending asynchronous operation started with BeginGetResponse(AsyncCallback, Object).

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext)

使用将目标对象序列化所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data needed to serialize the target object.

(继承自 WebRequest)
GetRequestStream()

检索用于向 FTP 服务器上载数据的流。Retrieves the stream used to upload data to an FTP server.

GetRequestStreamAsync()

当在子类中被重写时,将用于写入数据的 Stream 作为异步操作返回到 Internet 资源。When overridden in a descendant class, returns a Stream for writing data to the Internet resource as an asynchronous operation.

(继承自 WebRequest)
GetResponse()

返回 FTP 服务器响应。Returns the FTP server response.

GetResponseAsync()

当在子类中被重写时,将作为异步操作返回对 Internet 请求的响应。When overridden in a descendant class, returns a response to an Internet request as an asynchronous operation.

(继承自 WebRequest)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

当在子代类中重写时,使用序列化 SerializationInfo 所需要的数据来填充 WebRequest 实例。When overridden in a descendant class, populates a SerializationInfo instance with the data needed to serialize the WebRequest.

(继承自 WebRequest)

安全性

WebPermission
用于访问此请求引用的资源。for accessing the resource referenced by this request. 关联枚举:ConnectAssociated enumeration: Connect.

适用于

另请参阅