Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Ed Williams
Ed Williams
2,969 Points

How to do a POST request to a URL with Parameters in Swift?


I've followed the "Build a Weather App with Swift" Swift tutorial on making a call to a URL to obtain JSON, and I'm trying to adapt this. Can anyone explain how to make a POST request to a URL so I can pass parameters to it (for example, a username). I don't want to pass the parameters via the URL like in the tutorial.

let dataObject = NSData(contentsOfURL: location)
// Send username...
println(NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil))