Expected behavior:
Here I want to use shouldInterceptAjaxRequest
and change the request url and add header.
Current behavior:
Only request url be changed, header not working at all.
Steps to reproduce
I submit the source code https://github.com/norman93sun/flutter_inappwebview, you can run the flutter_inappwebview example
I init webview with
initialData: InAppWebViewInitialData(data: htmlString, baseUrl: WebUri('http://localhost'))
shouldInterceptAjaxRequest:
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
print('ajaxRequest ---------- ${ajaxRequest.toString()}');
/// change https://form.mcttechnology.cn/shtest-prod/shtest-0-ccn-uploadfiles-en/storage/s3
if (ajaxRequest.url.toString().contains('storage/s3')) {
ajaxRequest.url = WebUri.uri(Uri.parse(
'https://shtest-app-v2.mcttechnology.cn/api/platform/formio/shtest-0-ccn-uploadfiles-en/storage/s3'));
ajaxRequest.headers?.setRequestHeader('authorization',
'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6Ikl2VyJ9.eyJpc3MiOm51bGwsInN1YiI6MTExMTY1MjQxLCJpYXQiOjE3MjA1ODE3MTMsImV4cCI6MTcyMDYyNDkxMywiZW1haWwiOiIzMjY1NjQ0NTYxQHFxLmNvbSIsImdpdmVuX25hbWUiOiJzaHRlc3QiLCJmYW1pbHlfbmFtZSI6ImNqanl5IiwibmFtZSI6IjMyNjU2NDQ1NjFAcXEuY29tIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiMzI2NTY0NDU2MUBxcS5jb20iLCJqdGkiOjQsInVzZXJJZCI6bnVsbH0.uU0WVtEJoa3v17_UHKzaee1y2cFXdArvKQidylPa-YY');
}
return ajaxRequest;
},
Step: upload a image by tap browse. The get error.
If I dont InterceptAjaxRequest evrything go right like below:
But got 401 error when I changed the request url, but the authorization header I passed not working.
I suspect it’s a CORS problem, so how to fix this?