This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter] Webiew post url support #1970
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f701dd
added postUrl for Android webview
charafau c2606df
Merge branch 'master' into webiew_post_url_support
charafau 4a65213
added ios implementation
charafau 9dfdeee
Merge branch 'master' into webiew_post_url_support
charafau 6a913c8
Changed initial post parameters to controller postUrl
charafau 27260e0
Merge branch 'master' into webiew_post_url_support
charafau 0596136
reformatted code
charafau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// found in the LICENSE file. | ||
|
||
#import "FlutterWebView.h" | ||
#import <os/log.h> | ||
#import "FLTWKNavigationDelegate.h" | ||
#import "JavaScriptChannelHandler.h" | ||
|
||
|
@@ -98,6 +99,8 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | |
[self onUpdateSettings:call result:result]; | ||
} else if ([[call method] isEqualToString:@"loadUrl"]) { | ||
[self onLoadUrl:call result:result]; | ||
} else if ([[call method] isEqualToString:@"postUrl"]) { | ||
[self postUrl:call result:result]; | ||
} else if ([[call method] isEqualToString:@"canGoBack"]) { | ||
[self onCanGoBack:call result:result]; | ||
} else if ([[call method] isEqualToString:@"canGoForward"]) { | ||
|
@@ -340,6 +343,29 @@ - (bool)loadUrl:(NSString*)url withHeaders:(NSDictionary<NSString*, NSString*>*) | |
return true; | ||
} | ||
|
||
- (bool)postUrl:(FlutterMethodCall*)call result:(FlutterResult)result { | ||
NSDictionary<NSString*, NSObject*>* args = [call arguments]; | ||
|
||
NSString* url = (NSString*)args[@"url"]; | ||
NSURL* nsUrl = [NSURL URLWithString:url]; | ||
if (!nsUrl) { | ||
return false; | ||
} | ||
|
||
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; | ||
FlutterStandardTypedData* postData = (FlutterStandardTypedData*)args[@"params"]; | ||
NSString* contentLength = @(postData.data.length).stringValue; | ||
|
||
[request setHTTPMethod:@"POST"]; | ||
[request setHTTPBody:postData.data]; | ||
|
||
[request setValue:contentLength forHTTPHeaderField:@"Content-Length"]; | ||
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the Android webview forces this encoding, do you know if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if you can send multipart like that, but code I've seen uses form encoded only |
||
|
||
[_webView loadRequest:request]; | ||
return true; | ||
} | ||
|
||
- (void)registerJavaScriptChannels:(NSSet*)channelNames | ||
controller:(WKUserContentController*)userContentController { | ||
for (NSString* channelName in channelNames) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expecting a Map ->
application/x-www-form-urlencoded
encoding in each platform implementation sounds a little fragile in case these implementations don't exactly match.My preference would be to take a similar approach to Android's WebView and WkWebView where the encoding is the responsibility of the app developer, which allows some more flexibility for developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is how you're suppose to do that, webview send form by post with this.