Description
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 7.0.1
@capacitor/core: 7.0.1
@capacitor/android: 7.0.1
@capacitor/ios: 7.0.1
Installed Dependencies:
@capacitor/cli: 7.0.1
@capacitor/core: 7.0.1
@capacitor/android: 7.0.1
@capacitor/ios: 7.0.1
[success] iOS looking great! 👌
[success] Android looking great! 👌
Other API Details
alexryltsov@Alexs-MacBook-Pro-2 master % npm --version
10.5.0
alexryltsov@Alexs-MacBook-Pro-2 master % node --version
v20.11.1
alexryltsov@Alexs-MacBook-Pro-2 master % pod --version
1.16.2
Platforms Affected
- iOS
- Android
- Web
Current Behavior
Capacitor HTTP POST with ContentType application/x-www-form-urlencoded body not encoded on iOS (please note that it is properly encoded on Android so the behavior differs between these platform) - see below
Here is the request on iOS (note that the special characters are not encoded)
Here is the same request on Android (note that the special characters are properly encoded)
This causes the problem when the server does not recognize the content of the request as expected when sent from iOS platform (all works fine on Android)
It also seems that shouldEncodeUrlParams
HttpOption is not supported on iOS (see https://capacitorjs.com/docs/apis/http#httpoptions)
Expected Behavior
Request content/body encoding must be the same for the both iOS and Android platforms.
Project Reproduction
Additional Information
See README in the Project Reproduction repository for more details.
The potential fix encode before sending the request - see https://github.com/ryaa/capacitor-http-post-application-x-www-form-urlencoded-body-not-encoded-on-ios/blob/master/src/app/home/home.page.ts#L26 or fix Capacitor HTTP plugin - see #7841
Please note that for the latter fix only % is encoded on iOS (see below) but this fixes the problem on our end and the server correctly recognize the values
If shouldEncodeUrlParams
HttpOption support is added on iOS (see https://capacitorjs.com/docs/apis/http#httpoptions) this should allow to encode by default and still allow to avoid encoding as it is now (however, this still seems to be breaking change)