nsurlconnection

Ignoring certificate errors with NSURLConnection

梦想与她 提交于 2019-11-26 11:18:41
问题 I am getting this error The certificate for this server is invalid. You might be connecting to a server that is pretending to be \"server addres goes here\" which could put your confidential information at risk.\" I am using this method: [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; How can I fix this? I tried this code: NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; but then I get EXC_BAD_ACCESS in

NSURLConnection and Basic HTTP Authentication in iOS

蹲街弑〆低调 提交于 2019-11-26 11:04:41
I need to invoke an initial GET HTTP request with Basic Authentication . This would be the first time the request is sent to the server and I already have the username & password so there's no need for a challenge from the server for authorization. First question: Does NSURLConnection have to be set as synchronous to do Basic Auth? According to the answer on this post , it seems that you can't do Basic Auth if you opt for the async route. Anyone know of any some sample code that illustrates Basic Auth on a GET request without the need for a challenge response? Apple's documentation shows an

NSURLConnection and grand central dispatch

て烟熏妆下的殇ゞ 提交于 2019-11-26 10:09:41
问题 Is it advisable to wrap up NSUrlConnection in a gcd style blocks and run it on a low_priority queue? I need to ensure that my connections are not happening on the main thread and the connections need to be asynchronous. I also need several simultaneous requests to go at once. If I go the gcd route, I\'m not sure which thread the NSUrlConnectionDelegate methods get invoked on. NSURLConnection relies on delegates so once the connection is complete, whatever wrapper class that handles it will

why [response expectedContentLength] always return -1

那年仲夏 提交于 2019-11-26 09:34:17
问题 -(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; if([recievedData length]) [ recievedData setLength:0 ]; download_size =[response expectedContentLength]; } I have this code. download_size is NSInteger. expectedContentLenght always return: -1. Maybe someone know why? I tried use long, but effect was the same. Thanks for help. 回答1: The expected content length is only set when

Managing multiple asynchronous NSURLConnection connections

别来无恙 提交于 2019-11-26 09:29:43
I have a ton of repeating code in my class that looks like the following: NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; The problem with asynchronous requests is when you have various requests going off, and you have a delegate assigned to treat them all as one entity, a lot of branching and ugly code begins to formulate going: What kind of data are we getting back? If it contains this, do that, else do other. It would be useful I think to be able to tag these asynchronous requests, kind of like you're able to tag views with IDs. I was curious

NSURLConnection sendAsynchronousRequest:queue:completionHandler: making multiple requests in a row?

你离开我真会死。 提交于 2019-11-26 08:42:46
问题 I have been using NSURLConnection\'s sendAsynchronousRequest:queue:completionHandler: method which is great. But, I now need to make multiple requests in a row. How can I do this while still using this great asychronous method? 回答1: There's lots of ways you can do this depending on the behavior you want. You can send a bunch of asynchronous requests at once, track the number of requests that have been completed, and do something once they're all done: NSInteger outstandingRequests =

NSMutableURLRequest timeout interval not taken into consideration for POST requests

删除回忆录丶 提交于 2019-11-26 08:20:57
问题 I have the following problem. On a NSMutableURLRequest using the HTTP method POST the timeout interval set for the connection is ignored. If the internet connection has a problem (wrong proxy, bad dns) the url request fails after about 2-4 minutes but not with NSLocalizedDescription = \"timed out\"; NSUnderlyingError = Error Domain=kCFErrorDomainCFNetwork Code=-1001 UserInfo=0x139580 \"The request timed out. If the http method used is GET it works fine. The connection is async over https .

NSURLSession: How to increase time out for URL requests?

不羁的心 提交于 2019-11-26 08:09:29
问题 I am using iOS 7\'s new NSURLSessionDataTask to retrieve data as follows: NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest: request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { // }]; How can I increase the time out values to avoid the error \"The request timed out\" (in NSURLErrorDomain Code= -1001 )? I have checked the documentation for NSURLSessionConfiguration but did not find a way to set

How to send Asynchronous URL Request?

独自空忆成欢 提交于 2019-11-26 07:34:18
问题 I would like to know how do I get a return value 1 or 0 only.... back from an URL request asynchronously. currently I do it in this way: NSString *UTCString = [NSString stringWithFormat:@\"http://web.blah.net/question/CheckQuestions?utc=%0.f\",[lastUTCDate timeIntervalSince1970]]; NSLog(@\"UTC String %@\",UTCString); NSURL *updateDataURL = [NSURL URLWithString:UTCString]; NSString *checkValue = [NSString stringWithContentsOfURL:updateDataURL encoding:NSASCIIStringEncoding error:Nil]; NSLog(@\

Post data in Objective C using Json

倾然丶 夕夏残阳落幕 提交于 2019-11-26 07:29:28
问题 I am trying to post data to a PHP web service. I am familiar doing this in html using query $.post but I am very much stumped trying this in objective C. I tried several blogs & questions found on stackoverflow. I finally came up with the following code: NSString *jsonRequest = [NSString stringWithFormat:@\"{\\\"Email\\\":\\\"%@\\\",\\\"FirstName\\\":\\\"%@\\\"}\",user,fname]; NSLog(@\"Request: %@\", jsonRequest); NSURL *url = [NSURL URLWithString:@\"http:myurl...\"]; NSMutableURLRequest