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

iOS

Nicolo Figiani
Nicolo Figiani
4,012 Points

How to make an HTTP request for authentication in swift?

Hi everyone, I need to make the following HTTP request:

curl -H "Content-Type:application/json" -H "api_key:95640" -d "password" https://api.website.com/account.json/authenticate/username

I can make it work by using curl, but I'm quite in trouble when making the same HTTP request in swift.

How can I translate this request in swift? In particular, how can I add the "Content-Type" and the "api_key" as header's parameters?

Thanks a lot, bye!