使用Basic Authentication方式请求github的https://api.github.com/authorizations
final requestHeader = {'Authorization': 'Basic '+base64.encode(utf8.encode('$userName:$passWord'))};
final requestBody = json.encode({
'client_id': 'xxxxx',
'client_secret': 'xxxxxxxxx',
'scopes': ['user', 'repo', 'notifications']
});
try {
Response response;
Dio dio = new Dio();
response = await dio.post(
Api.authorizations,
data: requestBody,
options: Options(
headers: requestHeader,
),
);
return response;
} catch (e) {
print(e);
return null;
}
同样的参数,我使用postman进行请求返回成功,但是这里永远是401
@dlgchg 请问是什么原因引起的?
I solved this way:
var response = await Dio().post("http://myurl",
options: Options(
followRedirects: false,
validateStatus: (status) { return status < 500; }
),
);
Most helpful comment
I solved this way: