Swifthttp package is a third-party HTTP library under iOS official address: Https://github.com/daltoniam/SwiftHTTP
Project development If you want to use a third-party library, you need to use Cocoapods
Environment ready: Update Ruby gem into terminal, enter sudo gem update--system and endure, after installation, enter gem install cocoapods continue to endure, after installation, enter POD Setup Still endure. After completion, the installation and configuration of the cocoapods is completed;
The below describes the use. Using Xcode to create a new project, after the project is established, open the terminal and enter the root directory of the project, enter: Touch podfile open-e podfile and enter in the editorsource ' Https://github.com/CocoaPods/Specs.git ' Platform:ios, ' 8.0 ' use_frameworks! pod ' swifthttp ', ' ~> 0.9.2 ' Save the exit, and then enter in the terminal: pod Install This is cocoapods will automatically download and configure the dependencies, after the toss, will create a Pods folder in the root directory, as well as a. xcworkspace file
quit Xcode, and then double-click the newly generated. xcworkspace file to open Xcode. Until now, swifthttp third-party package installed;
How to use Swifthttp Import Swifthttp
then add the following code to the event, such as in the Login button click event:
@IBAction func Login (sender:anyobject) { var request = Httptask () let params:dictionary<string,anyobject > = ["Method": "Loginbyform", "U": "Login", "P": "2222"] request. POST ("Http://ip:port/webapp/wa", Parameters:params, Success: {(response:httpresponse) in//access succeeded in this write logic println ("info is \ (response.text ())") },failure: {(Error:nserror, response:httpresponse.) in //access failed }) c10/>}
Swift initiates HTTP POST request with Swifthttp package