Alamofire GET request, POST request, and upload dictionary

Source: Internet
Author: User

GET Request:

Alamofire.request ("Your URL", method:. Get, Parameters:nil, Encoding:URLEncoding.default)

. Responsejson {Response in

Print ("Url:\ (response.request)")//original URL request

Print ("Request:\ (response.response)")//URL response

Print ("Data:\ (response.data)")//Server data

Print ("Result:\ (Response.result)")//Result of response Serializatio

}

POST request:

Let currrequest = Alamofire.request ("Your URL", method:. Post, Parameters:nil, Encoding:URLEncoding.default, Headers:nil)

currrequest.responsejson{(Responsejson), Void in

Switch Responsejson.result {

Case. Success (let value):

Let Swiftyjsonvar = JSON (value)

Put all the title you get in the array

Let str = swiftyjsonvar["Data"].arrayvalue.map ({$0["title"].stringvalue})

Self.resultarr = swiftyjsonvar["Data"]

For index in 1...self.resultarr.count{

If let str = self.resultarr[index-1]["title"].string {

//

Print (str)

//                        }

//                    }

Case. Failure (_):

Print (Error)

Zhbpoptipview.showtext ("Network error", Position:. Bottom)

}

Self.tableView.reloadData ()

}


Post interface and upload the dictionary:

do {

DIC = ["Key": "Value"]

Print (Mobiledic)

Alamofire.request ("Your URL", method:. Post, Parameters:dic, Encoding:URLEncoding.default, Headers:nil). Responsejson ( Completionhandler: {(response) in

Switch response.result{

Case. Success:

Iflet dic:nsdictionary = (response.result.value as?) Nsdictionary) {

Print (DIC)

}

Case-Failure (let error):

Print (Error)

}

})

} catch {

Print (Error)

}

Alamofire GET request, POST request, and upload dictionary

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.