When opening HttpRequest I get this error: 2 positional arguments are expected, but 5 found

I wrote a form submission function in the REST API. Here is the code:

HttpRequest request; void submitForm(Event e) { e.preventDefault(); // Don't do the default submit. request = new HttpRequest(); request.onReadyStateChange.listen(onData); // POST the data to the server. var url = 'http://127.0.0.1:8000/api/v1/users'; request.open('GET', url, true, theData['userName'], theData['password']); request.send(); } 

From the documentation, you can have five arguments as follows when you open a query:

 void open(String method, String url, {bool async, String user, String password}) 

See here for more details.

As you can see, I used all 5 arguments, but for some reason I get this error:

 2 positional arguments expected, but 5 found 

Any suggestions as to why?

+4
source share
1 answer

Normal arguments are called positional arguments (for example, the method and url in this case). The arguments in braces are optional named parameters:

 void open(String method, String url, {bool async, String user, String password}) 

They are optional, you do not need to transfer them if you do not need them. Order is not important when making a call. If you need to pass them, attach them to the name and colon. In your case:

 request.open('GET', url, async: true, user: theData['userName'], password: theData['password']); 
+3
source

Source: https://habr.com/ru/post/1490056/