NSMutableURLRequest not obeying my timeoutInterval

There’s a thread on Apple dev forums discussing this issue. Apparently on iPhone OS, the setter mandates timeoutInterval a minimum of 240 seconds (4 minutes). This only occurs when the postBody is not empty (typically when using a POST request). This seems crazy, but apparently it’s there to make sure requests leave the system even … Read more

How to print NSMutableURLRequest?

.allHTTPHeaderFields returns a dictionary with the header content: NSLog(@”%@”, [request allHTTPHeaderFields]); // { // “Accept-Language” = “en;q=1”; // “Content-Length” = 190706; // “Content-Type” = “multipart/form-data; boundary=Boundary+D90A259975186725”; // “User-Agent” = “…”; // } Or for specific field: NSString *field = @”Content-Type”; NSLog(@”%@”,[request valueForHTTPHeaderField:field]); // multipart/form-data; boundary=Boundary+D90A259975186725

Creating NSData from NSString in Swift

In Swift 3 let data = string.data(using: .utf8) In Swift 2 (or if you already have a NSString instance) let data = string.dataUsingEncoding(NSUTF8StringEncoding) In Swift 1 (or if you have a swift String): let data = (string as NSString).dataUsingEncoding(NSUTF8StringEncoding) Also note that data is an Optional<NSData> (since the conversion might fail), so you’ll need to … Read more