Describe the bug
iOS and Android handle form-uurlencoded requests differently. I believe the intent is to require the data property to be an object when making a the request, but that's not enforced on the JavaScript side. At the iOS layer, if the data property is a string, it's sent straight though; Android, on the other hand, expects it to be an object, and throws an exception if it's not.
To Reproduce
Make a call to Http.request() like so:
const response = await Http.request(
{
"url":"https://foo.com",
"method":"POST",
"headers":{"Accept":"application/json","Content-Type":"application/x-www-form-urlencoded"},
"data":"a=b&b=c&c=d"
}
Expected behavior
The behavior should be the same on both Android and iOS. If the intention is that form requests must have data specified as an object, then both platforms should throw an exception. Otherwise, both should expect a raw string.
Smartphone (please complete the following information):
- Device: iPhone 11 Pro
- OS: iOS 15.5
- Browser [Capacitor web view]
- Simulator
Smartphone (please complete the following information):
- Device: Android Pixel 4
- OS: API 30
- Browser [Capacitor web view]
- Simulator
Additional context
Relevant Swift code:
|
if let strVal = try? getRequestDataAsString(body) { |
Relevant Java code:
|
JSObject obj = body.toJSObject(); |
Clearly the workaround here is to just pass an object, but fixing this would save folks time!
Describe the bug
iOS and Android handle form-uurlencoded requests differently. I believe the intent is to require the
dataproperty to be an object when making a the request, but that's not enforced on the JavaScript side. At the iOS layer, if thedataproperty is a string, it's sent straight though; Android, on the other hand, expects it to be an object, and throws an exception if it's not.To Reproduce
Make a call to Http.request() like so:
Expected behavior
The behavior should be the same on both Android and iOS. If the intention is that form requests must have
dataspecified as an object, then both platforms should throw an exception. Otherwise, both should expect a raw string.Smartphone (please complete the following information):
Smartphone (please complete the following information):
Additional context
Relevant Swift code:
http/ios/Plugin/CapacitorUrlRequest.swift
Line 100 in 3aca516
Relevant Java code:
http/android/src/main/java/com/getcapacitor/plugin/http/CapacitorHttpUrlConnection.java
Line 193 in 3aca516
Clearly the workaround here is to just pass an object, but fixing this would save folks time!