Categories
ios swift

Making an HTTP POST Request in Swift

In this example I will be uploading an image to a node.js server. func makePostRequest(){ // create a instantiate a session let session = NSURLSession.sharedSession() // set url to POST to var url = NSURL(string: “http://yourdomain.com/post”) // create the request object var request = NSMutableURLRequest(URL: url!) request.HTTPMethod = “POST” request.HTTPBody = YOUR_REQUEST_BODY // set up the […]

Categories
ios swift

Creating a POST request body in Swift

// createRequestBody() func createRequestBody(photo:NSData){ var boundary:String = “——WebKitFormBoundaryasdas543wfsdfs5453533d3sdfsf3” var contentType = “multipart/form-data; boundary=\(boundary)” request.HTTPMethod = “POST” request.addValue(contentType, forHTTPHeaderField: “Content-Type”) var body = NSMutableData() body.appendData(NSString(format: “\r\n–%@\r\n”, boundary).dataUsingEncoding(NSUTF8StringEncoding)!) body.appendData(NSString(format: “Content-Disposition: form-data; name=\”photo\”; filename=\”photo.jpeg\”\r\n”).dataUsingEncoding(NSUTF8StringEncoding)!) body.appendData(NSString(format:”Content-Type: image/jpeg\r\n\r\n”).dataUsingEncoding(NSUTF8StringEncoding)!) body.appendData(photo) body.appendData(NSString(format: “\r\n–%@\r\n”, boundary).dataUsingEncoding(NSUTF8StringEncoding)!) println(body) // This will be the request body to post to your api/service }  Example of request body […]

Categories
ios objective-c

Using SpinKit-ObjC

I was looking to create a custom activity indicator, but adding additional time to a project was not possible. I found this cool project SpinKit-ObjC that provides ready made indicators. Below is a demo of a few of them I checked out. https://github.com/raymondjavaxx/SpinKit-ObjC There are also best cialis online other ED drugs in the market, […]