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

GET urls that contain parameters an encoded incorrectly #279

Open
rickmeier1 opened this issue Jul 19, 2024 · 2 comments
Open

GET urls that contain parameters an encoded incorrectly #279

rickmeier1 opened this issue Jul 19, 2024 · 2 comments

Comments

@rickmeier1
Copy link

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.

@3lvis
Copy link
Owner

3lvis commented Jul 29, 2024

Thanks for reporting this bug, I have been trying to fix this as well without much luck, any ideas on how to fix it?

@rickmeier1
Copy link
Author

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.

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

No branches or pull requests

2 participants