arnemolland / sigv4

Dart library for signing AWS requests with Signature Version 4
MIT License
17 stars 23 forks source link

Error: XMLHttpRequest error. #32

Closed PeterTF656 closed 3 years ago

PeterTF656 commented 3 years ago

I am trying to send a get request to AWS. Here is my code in Flutter:

import 'package:http/http.dart';
import 'package:sigv4/sigv4.dart';

void main() async {
  final client = Sigv4Client(
    keyId: '***',
    accessKey: '***',
    region: '***',
    serviceName: '***',
  );

  final path =
      ***;
  final query = {'uniqUID': 'All'};
  final url = client.canonicalUrl(path, query: query);
  final headers = client.signedHeaders(
    path,
    query: query,
  );

  var response = await get(url, headers: headers);

  print(response);
}

And here is the error:

Error: XMLHttpRequest error.
    dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28                get current
packages/http/src/browser_client.dart 84:22                                       <fn>
dart-sdk/lib/async/zone.dart 1612:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 152:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 704:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 733:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 530:7                                         [_complete]
dart-sdk/lib/async/stream_pipe.dart 61:11                                         _cancelAndValue
dart-sdk/lib/async/stream.dart 1219:7                                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39  dcall
dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58                              <fn>

    at Object.createErrorWithStack (http://localhost:51205/dart_sdk.js:5347:12)
    at Object._rethrow (http://localhost:51205/dart_sdk.js:39349:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:51205/dart_sdk.js:39343:13)
    at Object._microtaskLoop (http://localhost:51205/dart_sdk.js:39175:13)
    at _startMicrotaskLoop (http://localhost:51205/dart_sdk.js:39181:13)
    at http://localhost:51205/dart_sdk.js:34688:9
PeterTF656 commented 3 years ago

Alright, guys, I solved this CORS issue by configuring my backend settings to accept CORS and also I disabled web security in flutter chrome starter...