Sending data from Dart to PHP using the POST method

I am trying to send some data from Dart to PHP ... This is the code that I use to send data from Dart:

button.onClick.listen((e) {
  var req = new HttpRequest();


  req.onReadyStateChange.listen((HttpRequestProgressEvent e) {
    if (req.readyState == HttpRequest.DONE) {
      print('Data submitted!');
    }
  });


  req.open('POST', form.action);
  req.send('hello from dart');

});

In my PHP file, I am trying to use a string that I sent from dart, but count ($ _ POST) returns 0. $ _POST seems empty ...

The dart code launches a php script and displays "Data Submitted" ...

+5
source share
2 answers

This is really related to your PHP configuration. You can access the POST data with the reserved PHP variable: $ HTTP_RAW_POST_DATA . However, the preferred method is to use php: // input

+7
source

Dart, FormData send. .

    var data_form = new FormData(query('#My_form'));

    button.onClick.listen((e){
           var request = new HttpRequest():
           request.open('POST', 'http://Localhost/form_data.php');
           request.send(data_form);
+2

All Articles