Fetch API Reference

Fetch 物件整合了 .NET 原生 WebRequestHttpClient 物件的優點,以單一物件提供方便的 HTTP 請求。

Struct

Struct 描述
Fetch() 初始化 Fetch
Fetch(String uri) 初始化 Fetch 的 uri

Property

名稱 類型 範圍 描述
uri string public 物件的 HTTP 請求資源路徑
binarySize int public 上傳檔案的最大限制 (byte) 預設 25*1024 (25MB)
header object public 送出請求時設定的 Header 物件,預設 null
userAgent string public 送出請求時自訂 User-Agent 字串,預設 null
contentType string public 送出請求時設定的 Contnet-Type,預設 application/json
isRaw bool public 是否使用原始資料傳送,預設 false (會轉換成 JSON)
webResponse WebResponse public 請求完成後所產生的結果物件
validPlatform bool public 是否加入平台認證訊息,預設 false
req WebRequest protected Fetch 底層的 WebRequest 物件
client HttpClient protected Fetch 底層的 HttpClient 物件
res HttpResponseMessage protected Fetch 底層的 HttpResponseMessage 物件
formData MultipartFormDataContent protected Fetch 底層的 MultipartFormDataContent 物件

Method

名稱 類型 描述
get(object qs) string 使用 HTTP GET 方法進行網路請求,qs 將會組成 uri 的 query string,可為 null
get<T>(object qs) T 同上敘述,但回傳資料若為 JSON 會自動填充到指定物件
getBinary(object qs) byte[] 使用 HTTP GET 方法進行網路請求,qs 將會組成 uri 的 query string,可為 null,請求後的結果將以 binary 的格式回傳 (下載功能)
post(object data, [object qs, [object files]]) string 使用 HTTP POST 方法進行網路請求,data 將會組成 json 的資料夾帶,可為 null,qs 將會組成 uri 的 query string,files 將會以 multipart/form-data 的格式將指定路徑的檔案都送出
post<T>(object data, [object qs, [object files]]) T 同上敘述,但回傳資料若為 JSON 會自動填充到指定物件
delete(object data, [object qs]) string 使用 HTTP DELETE 方法進行網路請求,data 將會組成 json 的資料夾帶,可為 null,qs 將會組成 uri 的 query string
delete<T>(object data, [object qs]) T 同上敘述,但回傳資料若為 JSON 會自動填充到指定物件
getResponse() string 字串表示,取得最後一個請求的回傳結果
getBinaryResponse() byte[] binary 表示,取得最後一個請求的回傳結果
getStatusCode() int 取得 HTTP 請求後的最終結果,如果尚未取得結果則為 0
getResponseHeaders() WebHeaderCollection 取得請求後回應的整個 Headers 結果,無法取得時回應 null
getResponseHeader(string key) string 取得請求後回應中指定 Key 的 Header 結果,無法取得時回應 null

results matching ""

    No results matching ""