0

I'm trying to do a POST with DART and I'm getting this error, for now I just want to print the message on server side to be sure that I'm receiving it, but I don't know how to interpretate the error:

  • in Server Side:

[WARNING] rpc: Response Status Code: 500 Headers: access-control-allow-credentials: true access-control-allow-origin: * cache-control: no-cache, no-store, must-revalidate content-type: application/json; charset=utf-8 expires: 0 pragma: no-cache Exception: RPC Error with status: 500 and message: Invalid argument(s)

  • in Client Side: enter image description here

At my client side in DART I have this code:

async.Future<core.List> loadFiles(heatMapMessages request){

  var _url=null;
  var _queryParams = new core.Map();
  var _uploadMedia = null;
  var _uploadOptions = null;
  var _downloadOptions = commons.DownloadOptions.Metadata;
  var _body = null;

  if (request != null) {
    _body = convert.JSON.encode(converterClass.toJson(request));
  }

  _url = "load";
  var _response = _requester.request(_url, "POST",
    body: _body,
    queryParams: _queryParams,
    uploadOptions: _uploadOptions,
    uploadMedia: _uploadMedia,
    downloadOptions: _downloadOptions);

  return _response.then((data) => converterClass.fromJson(data));
}

And receiving it on my server Side as:

  @ApiMethod(method: 'POST', path: 'load')
  Future<List<String>> loadFiles(heatMapMessages filename1) async{
    print("test "+filename1.jsonInfo);
  }
Clemens Tolboom
  • 1,872
  • 18
  • 30
Blackout
  • 157
  • 1
  • 3
  • 14

1 Answers1

1

If you do a POST request to a different domain than where your client application was initially loaded from, the browser sends a preflight request (request type OPTION). Your server needs to handle it and respond properly otherwise the browser won't make the actual POST request.

How to create/add middleware that adds default headers to each request shows how to do it using the shelf package.

You see that if the request method is OPTIONS it responds with headers

{
  'Access-Control-Allow-Origin': '*',
  'Content-Type': 'text/html'
}

Additional header parameters might be necessary depending on what you try to do.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567