當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Dart HttpRequest.postFormData用法及代碼示例

dart:html 庫中HttpRequest.postFormData 方法的用法介紹如下。

用法:

Future<HttpRequest> postFormData(
   String url,    
   Map<String, String> data,    
   {bool? withCredentials,    
   String? responseType,    
   Map<String, String>? requestHeaders,    
   void onProgress(
   ProgressEvent e   
)?}   
)

使用編碼為表單數據的指定數據發出服務器 POST 請求。

這大致相當於 getString 的 POST。此方法類似於發送具有更廣泛瀏覽器支持但僅限於字符串值的 FormData 對象。

如果提供了data,則鍵/值對是用Uri.encodeQueryComponent 編碼的URI,並轉換為HTTP 查詢字符串。

除非另有說明,否則此方法會附加以下標頭:

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

這是使用此方法的示例:

var data = { 'firstName' : 'John', 'lastName' : 'Doe' };
HttpRequest.postFormData('/send', data).then((HttpRequest resp) {
  // Do something with the response.
});

也可以看看:

相關用法


注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 postFormData method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。