NSUrlSessionHandler NSUrlSessionHandler NSUrlSessionHandler NSUrlSessionHandler Class


在使用 Xamarin stack (iOS、macOS、watchOS、tvOS) 的 Apple 平台上,由  HttpClient  使用的預設訊息處理常式The default message handler used by HttpClient on Apple platforms using the Xamarin stack (iOS, macOS, watchOS, tvOS)

public ref class NSUrlSessionHandler : System::Net::Http::HttpMessageHandler
public class NSUrlSessionHandler : System.Net.Http.HttpMessageHandler
type NSUrlSessionHandler = class
    inherit HttpMessageHandler
Public Class NSUrlSessionHandler
Inherits HttpMessageHandler


NSUrlSessionHandler 是 HTTP 用戶端處理常式, 會將其工作委派給 Apple 的內 NSUrlSession建。The NSUrlSessionHandler is an HTTP client handler that delegates its work to Apple’s built-in NSUrlSession.   當您編譯應用程式時, 這是預設值, 但您可以選取不同的處理常式, 在應用程式中手動退出宣告。  This is the default when you compile your application, but you can opt-out of it manually in your application by selecting a different handler.  

使用 Apple NSUrlSession 有一些優點, 而不是使用任何通訊端型的執行, 而是在行動裝置上, 它會自動代表您開啟無線電, 而您會在無線電關閉時避免可能的超時或錯誤。Using the Apple NSUrlSession has some advantages over using any socket-based implementation, the chief one being that on a mobile device, it will automatically turn on the radio on your behalf and you will avoid a potential timeout or an error if the radio is down.

此外, 您可以設定處理常式繼續進行下載, 即使您的應用程式已暫停或已停止執行。Additionally, you can configure the handler to continue your downloads even if your application is suspended or has stopped running.


NSUrlSessionHandler() NSUrlSessionHandler() NSUrlSessionHandler() NSUrlSessionHandler()

NSUrlSessionHandler 的預設函式會以設定為預設值的  NSUrlSessionConfiguration  設定處理常式,並將資源逾時自訂為 24 小時 (因為 Apple 本身的傳輸不支援無限逾時)。The default constructor for NSUrlSessionHandler configures the handler with a NSUrlSessionConfiguration set to the default value, and customizes the resources time out to be 24 hours (as infinite timeouts are not supported by Apple’s own transport).


AllowAutoRedirect AllowAutoRedirect AllowAutoRedirect AllowAutoRedirect

取得或設定允許自動重新導向的值。Gets or sets a value that allows automatic redirection. 其預設值為 trueIts default value is true.

Credentials Credentials Credentials Credentials

取得或設定這個處理常式所用的驗證資訊。Gets or sets authentication information used by this handler.

DisableCaching DisableCaching DisableCaching DisableCaching


Dispose() Dispose() Dispose() Dispose()

釋放 Unmanaged 資源,並處置 HttpMessageHandler 所使用的 Managed 資源。Releases the unmanaged resources and disposes of the managed resources used by the HttpMessageHandler.

(Inherited from HttpMessageHandler)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken) SendAsync(HttpRequestMessage, CancellationToken)

以非同步作業的方式傳送 HTTP 要求。Sends an HTTP request as an asynchronous operation.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)