0

I'm trying to create a cURL web request using the curl/curl.dart package. However, I get the error The argument type 'String' can't be assigned to the parameter type 'Uri'.. How do I convert String to Uri?

Here is my complete code:

final request = new Request("POST", "http://my.web.url/webservice/rest/server.php");

final wstoken = "my_token";
final moodlewsrestformat = "json";
final wsfunction = "core_user_create_users";
final username = "test_user_3";
final firstname = "John";
final lastname = "Doe";
final email = "[email protected]";
final password = "password_for_john";

request.bodyFields = {
  "wstoken" : wstoken,
  "moodlewsrestformat": moodlewsrestformat,
  "wsfunction": wsfunction,
  "users[0][username]" : username,
  "users[0][firstname]" : firstname,
  "users[0][lastname]" : lastname,
  "users[0][email]" : email,
  "users[0][password]" : password
};

print(toCurl(request));

1 Answer 1

2

With the help of the documentation, I saw that you could probably use the Uri.tryParse(urlString) method.

final request = new Request("POST", Uri.tryParse("http://my.web.url/webservice/rest/server.php"));

final wstoken = "my_token";
final moodlewsrestformat = "json";
final wsfunction = "core_user_create_users";
final username = "test_user_3";
final firstname = "John";
final lastname = "Doe";
final email = "[email protected]";
final password = "password_for_john";

request.bodyFields = {
  "wstoken" : wstoken,
  "moodlewsrestformat": moodlewsrestformat,
  "wsfunction": wsfunction,
  "users[0][username]" : username,
  "users[0][firstname]" : firstname,
  "users[0][lastname]" : lastname,
  "users[0][email]" : email,
  "users[0][password]" : password
};

print(toCurl(request));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.