DART post with multipart/form-data

前端 未结 2 497
名媛妹妹
名媛妹妹 2020-12-19 22:03

in DART lang, how to specify POST request Content-Type to be

multipart/form-data

My DART code is:



        
相关标签:
2条回答
  • 2020-12-19 22:40

    I think you should use HttpRequest.postFormData(url, data) here. Then you can use the following:

    FormData data = new FormData(); // from dart:html
    
    data.append(key, value);
    
    HttpRequest.request('/upload', method: 'POST', sendData: data).then((HttpRequest r) {
      // ...
    });
    

    Regards, Robert

    0 讨论(0)
  • 2020-12-19 22:43

    On the server it is supported by the http package. This package can also be used in the browser but it seems the multipart_request.dart file can't be imported in the browser because it uses dart:io;

    I suggest creating a feature request on http://dartbug.com/new.

    You could also try to copy the code from the [http] package and remove the references to the io package and use browser API instead.

    How it could be used on the server is shown here http://www.dartdocs.org/documentation/http/0.11.1+1/index.html#http/http.MultipartRequest

    0 讨论(0)
提交回复
热议问题