1

您好,我正在使用 Dio 发送 FormData,但是发送时,网站返回错误

    var formData = FormData.fromMap({
      "ctl00\$ScriptManager1": "ctl00\$UpdatePanel1",
      "__EVENTTARGET" :"ctl00\$cphPage\$productsControl",
      "__EVENTARGUMENT" : "",
      "__LASTFOCUS" : "",
      "PageLoadedHiddenTxtBox" : "Set",
      "Language" : "es-MX",
      "CurrentLanguage" : "es-MX",
      "Currency" : "",
      "__VIEWSTATE" :"/sadasd.....",
      "__VIEWSTATEGENERATOR" : "C0E71A90",
      "ctl00\$txtSearch" : "",
      "ctl00\$cphPage\$productsControl\$TopTools\$cbxSortType" : "",
      "ctl00\$cphPage\$productsControl\$TopTools\$cbxPageSize" : "-1",
      "ctl00\$taxes\$listCountries" : "54",
      "__ASYNCPOST" : "true",
      " " : ""
    });
var dio = Dio();
    dio.interceptors.add(InterceptorsWrapper(onRequest: (RequestOptions options) async {
      var customHeaders = {
        'content-type': 'text/html; charset=utf-8',
        'application':'x-www-form-urlencoded',
        'Cookie': 'uid=rBQBc2CisZdxWU5XBBmMAg==; ASP.NET_SessionId=tedc4xrih1hk1ykbdzlakuvb; ASPNET_Session=client=BLUR; ShopMSAuth=0102A9A3B88FC919D908FEA90B7DF1D119D908000442004C005500520000012F00FF'
        // other headers
      };
      options.headers.addAll(customHeaders);

      return options;
    }));
    Response response = await dio.post(url, data: formData, options: Options(
        contentType: 'text/html; charset=utf-8',
        followRedirects: true
    ));

    print(response.data);

当我检查浏览器的请求时,最后的请求有作为参数:

__ASYNCPOST :true
 :""

这样的表格会好吗?

4

1 回答 1

0

你可以走这条路

var formData = FormData.fromMap({
 'name': 'wendux',
 'age': 25,
 'file': await MultipartFile.fromFile('./text.txt',filename: 'upload.txt')
});
response = await dio.post('/info', data: formData);
于 2021-05-18T06:29:33.840 回答