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 can I get NSURLResponse body?

Why do you cancel the connection? After all, 404 can have content body as well. Just don’t cancel it, and let the program call the next delegate NSURLConnection method. When the data [the content body] is sent – (void)connection:(NSURLConnection *) didReceiveData:(NSData *) is called, you need to retrieve the data there. Read corresponding part in … Read more

SSL Error in Connection to Server through iPhone

iOS 9 forces connections that are using HTTPS to be TLS 1.2 to avoid recent vulnerabilities. In iOS 8 even unencrypted HTTP connections were supported, so that older versions of TLS didn’t make any problems either. As a workaround, you can add this code snippet to your Info.plist: <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> Thereby you’re … Read more

NSData and Uploading Images via POST in iOS

This code works in my app. If you’re not using ARC you’ll need to modify the code to release anything alloc’ed. // create request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; [request setHTTPShouldHandleCookies:NO]; [request setTimeoutInterval:30]; [request setHTTPMethod:@”POST”]; // set Content-Type in HTTP header NSString *contentType = [NSString stringWithFormat:@”multipart/form-data; boundary=%@”, boundary]; [request setValue:contentType forHTTPHeaderField: @”Content-Type”]; … Read more

NSURLConnection/NSURLRequest gzip support

although it does not seem to be documented, there is evidence that NSURLConnection does have transparent gzip support. meaning that if the server supports gzip encoding, and your request has an Accept-Encoding header containing gzip*, the server will send a gzipped response, which NSURLConnection will automatically decode. * NSURLRequest might add that header by default. … Read more

Add HTTP Header to NSURLRequest

I don’t think you can modify the HTTP Headers of a NSURLRequest. I think you’re trying to modify a NSURLRequest object that you didn’t initialize? You could create a mutableCopy of your request and then set the header fields with the following method: -(void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field. After that you can copy the mutable request … Read more

NSURLConnection Using iOS Swift

Check Below Codes : 1. SynchronousRequest Swift 1.2 let urlPath: String = “YOUR_URL_HERE” var url: NSURL = NSURL(string: urlPath)! var request1: NSURLRequest = NSURLRequest(URL: url) var response: AutoreleasingUnsafeMutablePointer<NSURLResponse?>=nil var dataVal: NSData = NSURLConnection.sendSynchronousRequest(request1, returningResponse: response, error:nil)! var err: NSError println(response) var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataVal, options: NSJSONReadingOptions.MutableContainers, error: &err) as? NSDictionary println(“Synchronous\(jsonResult)”) Swift 2.0 + … Read more

How To Check Response.statusCode in sendSynchronousRequest on Swift

you pass in a reference to response so it is filled THEN you check the result and cast it to a HTTPResponse as only http responses declare the status code property. let urlPath: String = “http://www.google.de” var url: NSURL = NSURL(string: urlPath) var request: NSURLRequest = NSURLRequest(URL: url) var response: NSURLResponse? var data = NSURLConnection.sendSynchronousRequest(request, … Read more