Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Last active March 26, 2017 16:42
Show Gist options
  • Save jpotts18/8ddf31894b0bc053de24 to your computer and use it in GitHub Desktop.
Save jpotts18/8ddf31894b0bc053de24 to your computer and use it in GitHub Desktop.
Swift and AFNetworking
// In your Bridging-Header file
#import <AFNetworking/AFNetworking.h>
// initialize manager
let manager = AFHTTPRequestOperationManager()
// set headers
manager.requestSerializer.setValue("608c6c08443c6d933576b90966b727358d0066b4", forHTTPHeaderField: "X-Auth-Token")
// set parameters
var parameters = ["user":"admin", "password","correcthorsebatterystapler"]
// make request
manager.GET("http://somendpoint.com/requests",
parameters: nil,
success: { (operation:AFHTTPRequestOperation!, responseObject:AnyObject!) -> Void in
// success closure
println("JSON \(responseObject.description)")
}) { (operation:AFHTTPRequestOperation!, error:NSError!) -> Void in
// failure closure
println("JSON \(error.description)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment