nsmutableurlrequest

Creating NSData from NSString in Swift

牧云@^-^@ 提交于 2019-11-26 19:34:49
I'm trying to ultimately have an NSMutableURLRequest with a valid HTTPBody , but I can't seem to get my string data (coming from a UITextField ) into a usable NSData object. I've seen this method for going the other way: NSString(data data: NSData!, encoding encoding: UInt) But I can't seem to find any documentation for my use case. I'm open to putting the string into some other type if necessary, but none of the initialization options for NSData using Swift seem to be what I'm looking for. In Swift 3 let data = string.data(using: .utf8) In Swift 2 (or if you already have a NSString instance)

Sending a POST request from Cocoa to Tumblr

心已入冬 提交于 2019-11-26 13:04:14
问题 This code snippet isn\'t working, I\'m getting an \"Authentication Failed.\" response from the server. Any ideas? NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@\"http://www.tumblr.com/api/write\"]]; [request setHTTPMethod:@\"POST\"]; [request addValue:_tumblrLogin forHTTPHeaderField:@\"email\"]; [request addValue:_tumblrPassword forHTTPHeaderField:@\"password\"]; [request addValue:@\"regular\" forHTTPHeaderField:@\"type\"]; [request addValue:@\

Creating NSData from NSString in Swift

时光怂恿深爱的人放手 提交于 2019-11-26 07:07:08
问题 I\'m trying to ultimately have an NSMutableURLRequest with a valid HTTPBody , but I can\'t seem to get my string data (coming from a UITextField ) into a usable NSData object. I\'ve seen this method for going the other way: NSString(data data: NSData!, encoding encoding: UInt) But I can\'t seem to find any documentation for my use case. I\'m open to putting the string into some other type if necessary, but none of the initialization options for NSData using Swift seem to be what I\'m looking