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

fix a parameter name issue, add a synchronous request call #2

Closed
wants to merge 3 commits into from
Closed

fix a parameter name issue, add a synchronous request call #2

wants to merge 3 commits into from

Conversation

georgetso
Copy link

let request = YYHRequest(url: NSURL(string: "http://www.google.com/"))
request.parameters["name"] = "value"

Microsoft IIS would've got a parameter name as "?name". This patch fixed it.

@@ -63,20 +70,29 @@ public class YYHRequest: NSObject, NSURLConnectionDataDelegate {
}

public func loadRequest() {
if (parameters.count > 0) {
if (parameters.count > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation in this file seems to be really off, lots of extra spaces

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was in TextMate and didn't notice that, sorry.

@angelodipaolo
Copy link
Contributor

@georgetso I'm not sure I understand the issue with the query string. Query strings are required to start with ?.


let request = YYHRequest(url: NSURL(string: "http://www.google.com/"))

let responseData = request.loadImmediately()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the benefit of loading requests synchronously?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my project I need a synchronous request, so I put it in in case other people would need it, too.

@georgetso
Copy link
Author

Yes, a question mark should be leading parameters like http://www.google.com/?name=value&foo=bar
However, Microsoft IIS will see a parameters list in your project like this:
["?name": "value", "foo": "bar"]

after I removed that "?" in code, everything works as expected.

@angelodipaolo
Copy link
Contributor

@georgetso this sounds like a misconfiguration on your server. The ? is required in URLs that have query parameters, it cannot be removed.

@georgetso
Copy link
Author

I don't know, man. I'm not a server guy, never get my hands on IIS. The server guy told me the question mark thing, I have to believe him.
But strange is, I deleted the question mark, and everything just works. If it's a mistake to delete it, why it works?

@angelodipaolo
Copy link
Contributor

I see your issue now.

GET requests serialize the parameters as query string values. POST, PUT, DELETE serialize the parameters in the request body. The ? was mistakenly prepended to the request body when it should have only been used in the query string for GET requests. Thanks for bringing this to my attention.

2cfe31f fixes the issue

@georgetso
Copy link
Author

great, glad to help, and thanks for the wonderful job. Your work saved lot of my time.

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

Successfully merging this pull request may close these issues.

None yet

2 participants