How do I return a custom response to a Fetch request from Flutter InAppWebView? - flutter

I have a mobile flutter app that uses a flutter_inappwebview. In the webview, I have a mapbox-gl script to display a map. When requesting sprites, the script will make a fetch request to "https://content/sprite/sprite#2x.json", which I am able to capture using shouldInterceptFetchRequest. I would like the response to this request to contain a custom json file that I generate in my code.
In native Android, I am familiar with shouldInterceptRequest, which allows me to return a custom web resource response. However, the shouldInterceptFetchRequest in flutter_inappwebview requires me to return a FetchRequest. It seems the intent of shouldOverrideFetchRequest is to change the request before sending it from within the webview. Instead, I would like to create my own response, similar to the native Android method.
How do I supply a custom response to an inappwebview fetch request?

Related

Data coverts to some other form while sending an API request in my Flutter App

I am trying to send an API request in my flutter App for filtering the items in my app. I want the data to be filtered between certain 2 numbers.
This is what I want.
http://3.237.223.130/careWorker/get-parttime-jobList?workingHoursFrom=02.30&workingHoursTo=03.00
but the API call going from the app looks like this
http://3.237.223.130/careWorker/get-parttime-jobList?workingHoursFrom=02%3A30&workingHoursTo=03%3A00
The '.' is being converted into '%3A'
How can I send the API request in the form I want?
Both of them is the same value.
Seems like the query parameters are being urlEncoded while sending via API.
I have attached the image to show you the example.
You can test the URL encoded and decoded value HERE.

How do I save session cookie from response in flutter?

Let's say I log into an api with my flutter app. In an website, they automatically store the login cookie and then can use it. But in flutter app, how do I store the cookies and session? And how do I pass that into post to let the api know I have a valid login session?
Q: It's making me more confused, I just want the part to extract
cookie and how to use it.
There are a number of complexities, depending on exactly what you ultimately want to do.
But let's assume:
Your Flutter app makes an HTTP request (GET, PUT, etc.)
The server (e.g. your Flask app) returns cookies in the HTTP response (in the HTTP response header).
Let's further assume your HTTP code looks something like this:
Future<http.Response> fetchAlbum() {
return http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
}
In that case, you should be able to reference the cookies property of the Response object returned from the server.
SUGGESTION: See also these links:
Flutter For Web Cookie/Token Sessions and Authentication
Add Session Support to Flutter with Flutter Session

How to get data back when you launch the URL in Flutter web

I've one slack URL which I am opening using URL launched and in that URL I need to login to slack and after that, it gives me some JSON response that response I want back in the app. I've tried some solutions but it didn't work.
The URL will return me JSON data
PS : I am using Flutter web so i want it to be worked in Web

how to send POST HTTP request from Google Chrome without any extensions?

Can we send POST HTTP requests in Google Chrome when using Rest Services?
I have tried few extensions but I need directly from Chrome browser
I think, using the URL bar will always result in a GET.
To send POST requests from a browser, set up an HTML <form> with method="POST", use the action attribute for the REST-URL and input tags for other parameters.
You can do the post and get in the same way as the browser does.
You can use the header to put in information in key, value pair.
Here is a tutorial on how you can do it - Send POST data using XMLHttpRequest
But it would be better if you use chrome extension POSTMAN which is very extensive and clean for testing REST services.

Swift - Check if responsive or native app

I created a responsive app and a native app: the native app is basically just a UIWebView containing the responsive app.
How can i check on server side (php, etc..) where the request comes from?
Is there any possibility to modifiy requests sent from UIWebView or something else?
I see two possible approaches:
URL parameter
You could have a parameter in your URL to indicate the source of the request.
For instance, if the URL if your web app is
http://myserver.com/mypath
you could use the following URL in your native app's UIWebView:
http://myserver.com/mypath?src=native
On server side, you can retrieve this paramerer, e.g in PHP:
$src = $_GET['src'];
if ($src == 'native') {
// Request from native app
}
If your app has multiple pages, then you should modify the way your links are created to propagate this parameter when navigating from one page to another one.
Cookie
In the native app, you could manually set a custom cookie which would be sent along your requests and which you would retrieve on server side.
The following post may help you for that: Is it possible to set a cookie manually using sharedHTTPCookieStorage for a UIWebView?