HTTP Post passing 2 parameters and content type key flutter
up vote
0
down vote
favorite
I am struggling with making a http post call returning JSON in flutter. I keep getting a 500 error and I dont know what the issue is. I need to pass a username and password in the header and I think the issue is how im doing it. Here is the code.
Future<User> LoginUser(String username, String password ) async {
final response =
await http.post('http://xx.xxx.xxx.xxx/api/Login',
headers: {"Content-Type": "application/json", 'email' : username , 'password' : password });
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
return User.fromJson(json.decode(response.body));
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load user');
}
}
It wont get past the 200 check because it is getting a 500. I cant find any examples with passing 2 parameters in the header and the content type so im not sure im doing that correctly.
dart flutter
add a comment |
up vote
0
down vote
favorite
I am struggling with making a http post call returning JSON in flutter. I keep getting a 500 error and I dont know what the issue is. I need to pass a username and password in the header and I think the issue is how im doing it. Here is the code.
Future<User> LoginUser(String username, String password ) async {
final response =
await http.post('http://xx.xxx.xxx.xxx/api/Login',
headers: {"Content-Type": "application/json", 'email' : username , 'password' : password });
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
return User.fromJson(json.decode(response.body));
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load user');
}
}
It wont get past the 200 check because it is getting a 500. I cant find any examples with passing 2 parameters in the header and the content type so im not sure im doing that correctly.
dart flutter
1
It would be extremely unusual to send credentials as HTTP headers. Additionally, you are setting the request content type toapplication/json
, but then not including any content! Are you sure the credentials aren't meant to go in the post form or body?
– Richard Heap
Nov 8 at 0:05
that appears to be the issue. The credentials are supposed to be in the body.
– Sam Cromer
Nov 8 at 14:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am struggling with making a http post call returning JSON in flutter. I keep getting a 500 error and I dont know what the issue is. I need to pass a username and password in the header and I think the issue is how im doing it. Here is the code.
Future<User> LoginUser(String username, String password ) async {
final response =
await http.post('http://xx.xxx.xxx.xxx/api/Login',
headers: {"Content-Type": "application/json", 'email' : username , 'password' : password });
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
return User.fromJson(json.decode(response.body));
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load user');
}
}
It wont get past the 200 check because it is getting a 500. I cant find any examples with passing 2 parameters in the header and the content type so im not sure im doing that correctly.
dart flutter
I am struggling with making a http post call returning JSON in flutter. I keep getting a 500 error and I dont know what the issue is. I need to pass a username and password in the header and I think the issue is how im doing it. Here is the code.
Future<User> LoginUser(String username, String password ) async {
final response =
await http.post('http://xx.xxx.xxx.xxx/api/Login',
headers: {"Content-Type": "application/json", 'email' : username , 'password' : password });
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
return User.fromJson(json.decode(response.body));
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load user');
}
}
It wont get past the 200 check because it is getting a 500. I cant find any examples with passing 2 parameters in the header and the content type so im not sure im doing that correctly.
dart flutter
dart flutter
asked Nov 7 at 20:22
Sam Cromer
515
515
1
It would be extremely unusual to send credentials as HTTP headers. Additionally, you are setting the request content type toapplication/json
, but then not including any content! Are you sure the credentials aren't meant to go in the post form or body?
– Richard Heap
Nov 8 at 0:05
that appears to be the issue. The credentials are supposed to be in the body.
– Sam Cromer
Nov 8 at 14:13
add a comment |
1
It would be extremely unusual to send credentials as HTTP headers. Additionally, you are setting the request content type toapplication/json
, but then not including any content! Are you sure the credentials aren't meant to go in the post form or body?
– Richard Heap
Nov 8 at 0:05
that appears to be the issue. The credentials are supposed to be in the body.
– Sam Cromer
Nov 8 at 14:13
1
1
It would be extremely unusual to send credentials as HTTP headers. Additionally, you are setting the request content type to
application/json
, but then not including any content! Are you sure the credentials aren't meant to go in the post form or body?– Richard Heap
Nov 8 at 0:05
It would be extremely unusual to send credentials as HTTP headers. Additionally, you are setting the request content type to
application/json
, but then not including any content! Are you sure the credentials aren't meant to go in the post form or body?– Richard Heap
Nov 8 at 0:05
that appears to be the issue. The credentials are supposed to be in the body.
– Sam Cromer
Nov 8 at 14:13
that appears to be the issue. The credentials are supposed to be in the body.
– Sam Cromer
Nov 8 at 14:13
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197239%2fhttp-post-passing-2-parameters-and-content-type-key-flutter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It would be extremely unusual to send credentials as HTTP headers. Additionally, you are setting the request content type to
application/json
, but then not including any content! Are you sure the credentials aren't meant to go in the post form or body?– Richard Heap
Nov 8 at 0:05
that appears to be the issue. The credentials are supposed to be in the body.
– Sam Cromer
Nov 8 at 14:13