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

Custom POST body not being sent in v3.1.5 #1032

Closed
wvrfish opened this issue Jan 28, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@wvrfish
Copy link

commented Jan 28, 2016

Hi

This morning I updated Alamofire from 3.1.3 to 3.1.5 and since then my custom POST requests no longer include the POST body. I downgraded back to 3.1.3 and it worked again. I couldn't see anything in the changelog that might explain it so wondered if anyone could shed any light on it. Request creation code as follows:

self.manager.request(httpMethod, url, headers: headers, parameters: [:], encoding: .Custom({ (convertible, _) -> (NSMutableURLRequest, NSError?) in
            let mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest
            if let j = json {
                mutableRequest.HTTPBody = j.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
            }
            return (mutableRequest, nil)
        }))

where json is a pre-encoded json string.

Thanks #

@cnoon

This comment has been minimized.

Copy link
Member

commented Feb 4, 2016

Hi @adamjweaver, the reason that it is no longer being called is that we no longer call the .Custom closure in the event that there are no parameters being passed in. This was changed in the 3.1.4 release. However, due to several issues being opened on this topic, we're debating as to whether reverse the logic. Please hold tight for now while we figure this out. For now, you'll need to stay on the 3.1.3 release unless you can find another workaround.

We don't intend the .Custom encoding to be used unless you actually have parameters to encode. However, we've had multiple reports of users using this for other things than what it was intended.

@cnoon

This comment has been minimized.

Copy link
Member

commented Feb 7, 2016

Okay @adamjweaver, thanks for your patience. We've decided to revert the changes in 75c269a and instead handle the case of an empty query string properly for URL encoding. I've fixed up the issue in 8b618c7 if you want to check it out. These changes will be available in the 3.2.0 which we are working on right now.

Cheers. 🍻

@cnoon cnoon closed this Feb 7, 2016

@cnoon cnoon added this to the 3.2.0 milestone Feb 7, 2016

@Junus

This comment has been minimized.

Copy link

commented Feb 29, 2016

@cnoon Hi! looks like version 3.2.0 doesn't work. When I'm sending .POST request body is empty, but when I'm using .PUT everything ok

encoding = .Custom({convertible, params in
                let mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest
                mutableRequest.HTTPBody = body
                return (mutableRequest, nil)
            })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.