Post request with API Key and Webview Flutter

1,250 views
Skip to first unread message

Niladri Paul

unread,
Nov 7, 2019, 7:18:06 AM11/7/19
to Flutter Development (flutter-dev)
Dear All,

I have a flask application which once called from my flutter app, creates some HTML file and returns the location of the file name. Then my flutter app views that file using 'webview_flutter' package.  This was working perfectly fine in local development server. When I uploaded it to AWS, I secured the application with some API key. So my question is how to call this api now with this key using http.post and then view the created html file with 'webview_flutter package' and that api_key.  Kindly help me with this.

Thanks,
Niladri

Ahmed Olanrewaju

unread,
Nov 7, 2019, 7:55:34 AM11/7/19
to Flutter Development (flutter-dev)
You can use flutter http.post in the format below to add header credentials to your post request. body will be the actual data you are sending. This snippet is from one of my use case

Map<String, dynamic> body = {
'data': json.encode(
{'USER_NAME': email, 'PASSWORD': password, "AUTH_TYPE": "LOGIN"},
),
'actionType': 'LOGIN SELECT',
'sessionId': '0',
};

String url = '${Swift.apiUrl}/login';
final response = await http.post(
url,
body: body,
headers: {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded" "Authorization": "Apitoken yourpasskeystring"
},
encoding: Encoding.getByName("utf-8"),
);
Reply all
Reply to author
Forward
0 new messages