I am trying to make an HTTP POST request with the flutter plugin HTTP but I am getting an error of the title. Does anyone know the cause of this since in my other applications this works just perfectly fine?
await http.post(Uri.encodeFull("https://api.instagram.com/oauth/access_token"), body: {
"client_id": clientID,
"redirect_uri": redirectUri,
"client_secret": appSecret,
"code": authorizationCode,
"grant_type": "authorization_code"
});
To improve compile-time type safety, package:http
0.13.0 introduced breaking changes that made all functions that previously accepted Uri
s or String
s now accept only Uri
s instead. You will need to explicitly use Uri.parse
to create Uri
s from String
s. (package:http
formerly called that internally for you.)
Old Code | Replace With |
---|---|
http.get(someString) |
http.get(Uri.parse(someString)) |
http.post(someString) |
http.post(Uri.parse(someString)) |
(and so on.)
In your specific example, you will need to use:
await http.post(
Uri.parse("https://api.instagram.com/oauth/access_token"),
body: {
"client_id": clientID,
"redirect_uri": redirectUri,
"client_secret": appSecret,
"code": authorizationCode,
"grant_type": "authorization_code",
});
Since I'm still getting upvotes on this answer over a year later, it seems that there are still many people encountering this problem, probably from outdated tutorials. If so, while I appreciate the upvotes, I strongly recommend leaving comments on those tutorials to request that they be updated.
String url ='example.com';
http.get(Uri.parse(url),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With