How to make an HTTP request in Swift?

Posted by Rohit Kumar | Updated on

Want to make an HTTP request in Swift? You can use URL, URLRequest and URLSession or NSURLConnection as you’d normally do in Objective-C. Note that for iOS 7.0 and later, URLSession is preferred. Initialize a URL object and a URLSessionDataTask from URLSession. Then run the task with resume().

Using NSURLConnection

First, initialize a URL and a URLRequest:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers