Swift initiates HTTP POST request with Swifthttp package

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.