Created
January 27, 2015 06:33
-
-
Save mmtootmm/71a24cf14c60bb08809e to your computer and use it in GitHub Desktop.
HTTPBodyStream -> String in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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