GET urls that contain parameters an encoded incorrectly
rickmeier1 opened this issue · 2 comments
Describe the bug
If you provide parameters to a Networking.get() command the URL that is generated will UTF8 encode the parameters and you get an invalid URL:
http://www.apple.com/?test=3 -> http://www.apple.com/%3Ftest=3
To Reproduce
Try a test with this code:
let networking = Networking(baseURL: "https://httpbin.org")
let result = try await networking.get("/get",
parameters: [
"id":"7"
])
Expected behavior
Return JSON result like:
{
"args": {
"id": "7"
},
"headers": {
"Accept": "/",
"Host": "httpbin.org",
"User-Agent": "curl/8.6.0",
"X-Amzn-Trace-Id": "Root=1-669ae9cd-10e47d480029deb76b63a84b"
},
"origin": "---",
"url": "https://httpbin.org/get?id=7"
}
It will actually fail with:
Error Domain=com.3lvis.networking Code=404 "not found" UserInfo={NSLocalizedDescription=not found}
<NSHTTPURLResponse: 0x60000249c020> { URL: https://httpbin.org/get%3Fid=7 } { Status Code: 404, Headers {
"Access-Control-Allow-Origin" = (
"*"
);
"Content-Length" = (
233
);
"Content-Type" = (
"text/html"
);
Date = (
"Fri, 19 Jul 2024 22:37:35 GMT"
);
Server = (
"gunicorn/19.9.0"
);
"access-control-allow-credentials" = (
true
);
} }
Screenshots
iOS Version (please complete the following information):
MacOS: 14.5
Framework Version (please complete the following information):
6.12
Additional context
Should not be encoding the ? in a URL.
Thanks for reporting this bug, I have been trying to fix this as well without much luck, any ideas on how to fix it?
Probably just need to parse out the query parts (separated by ?, &), encode them and rebuild the request. It is just the "?" and "&" that should not be encoded.