I\'m trying to send an audio file to a PHP server. Here is the Objective-C code:
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSLog(@\"File Size
In swift you can post like this..
func wsPostData(apiString: String, jsonData: String) -> Void
{
//apiString means base URL
let postData = jsonData.dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: true)
let postLenth = "\(UInt((postData?.length)!))"
let request = NSMutableURLRequest()
request.URL = NSURL(string: apiString)
request.HTTPMethod = "POST"
request.setValue(postLenth, forHTTPHeaderField: "Content-Lenth")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.HTTPBody = postData
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response: NSURLResponse?, data: NSData?, error:NSError?) in
print("response\(response)")
var dict:NSDictionary!
do {
dict = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? [String: AnyObject]
print(" responce data is \(dict)")
}
catch let error as NSError
{
print("Something went wrong\(error)")
}
}
}