Skip to content

Instantly share code, notes, and snippets.

@mmtootmm
Created January 27, 2015 06:33
Show Gist options
  • Save mmtootmm/71a24cf14c60bb08809e to your computer and use it in GitHub Desktop.
Save mmtootmm/71a24cf14c60bb08809e to your computer and use it in GitHub Desktop.
HTTPBodyStream -> String in Swift
var data = NSMutableData()
var buffer = [UInt8](count: 4096, repeatedValue: 0)
request.HTTPBodyStream?.open()
while request.HTTPBodyStream!.hasBytesAvailable {
let length = request.HTTPBodyStream!.read(&buffer, maxLength: 4096)
if length == 0 {
break
} else {
data.appendBytes(&buffer, length: length)
}
}
println(NSString(data: data, encoding: NSUTF8StringEncoding)!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment