Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Capacitor HTTP POST application/x-www-form-urlencoded body not encoded on iOS #7840

Open
1 of 3 tasks
ryaa opened this issue Jan 23, 2025 · 0 comments
Open
1 of 3 tasks
Labels

Comments

@ryaa
Copy link
Contributor

ryaa commented Jan 23, 2025

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)
Image

Here is the same request on Android (note that the special characters are properly encoded)
Image

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

https://github.com/ryaa/capacitor-http-post-application-x-www-form-urlencoded-body-not-encoded-on-ios

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
Image

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant