nsurlconnection

Authentication with NSURLConnection sendAsynchronousRequest with completion handler

依然范特西╮ 提交于 2019-12-28 12:09:30
问题 Generally I like to just "fire and forget" with NSURL's sendAsynchronousRequest class method using the completion handler block but it seems that might not be an option when authentication is needed. When using a completion handler style request like this: [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mysite.com/"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { //Do

Create SSL connection using certificate

拈花ヽ惹草 提交于 2019-12-28 11:56:25
问题 I have ssl certificate (.cer) which was provided to me as file. I added it to bundle and want to use it communicating with server. I used apple provided code: - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ DLog(@"didReceiveAuthenticationChallenge : %@",challenge); if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { NSString *filePath = [[NSBundle mainBundle]

asynchronous upload with NSURLSession will not work but synchronous NSURLConnection does

荒凉一梦 提交于 2019-12-28 05:42:27
问题 edit: I need to upload a file asynchronously from an iPhone to a Python server-side process. I'd like to do the request asynchronously so that I can display a busy animation while it's working. The request needs to include the username, password and file as 'multipart/form-data'. I can get it working synchronously using NSURLConnection with the code looking like this:: -(void) uploadDatabase{ Database *databasePath = [[Database alloc] init]; NSString *targetPath = [databasePath

How to find size of a file before downloading it in iOS 7?

元气小坏坏 提交于 2019-12-28 03:10:09
问题 Wanted to find size of a file on some server before downloading it in iOS 7... I have a method of NSURLConnectionDelegate but it is deprecated after iOS 4.3 Here was that method: - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 回答1: You should instead use the NSURLConnectionDataDelegate Note : DATADelegate and its didReceiveResponse: method to send a HEAD request to get just the header: - (void)connection:(NSURLConnection *)connection

NSURLConnection sendAsynchronousRequest can't get variable out of closure

本秂侑毒 提交于 2019-12-27 12:05:53
问题 I'm trying to get a simple text response from a PHP page using POST. I have the following code: func post(url: String, info: String) -> String { var URL: NSURL = NSURL(string: url)! var request:NSMutableURLRequest = NSMutableURLRequest(URL:URL) var output = "Nothing Returned"; request.HTTPMethod = "POST"; var bodyData = info; request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding); NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()){ response,

Sending data to web form using POST from iPhone app

99封情书 提交于 2019-12-25 19:06:02
问题 I am trying to send data(a username and password) to an online form from my iPhone app using GET. This is my source code, but the problem is that no data gets stored in my database. NSString *post =[[NSString alloc] initWithFormat:@"email=%@&password=%@",enterUserName.text,enterPass.text]; NSURL *url=[NSURL URLWithString:@"http://planetimpressions.com/contacts/imagecomm_register.php"]; NSLog(post); NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

Sending data to web form using POST from iPhone app

陌路散爱 提交于 2019-12-25 19:05:53
问题 I am trying to send data(a username and password) to an online form from my iPhone app using GET. This is my source code, but the problem is that no data gets stored in my database. NSString *post =[[NSString alloc] initWithFormat:@"email=%@&password=%@",enterUserName.text,enterPass.text]; NSURL *url=[NSURL URLWithString:@"http://planetimpressions.com/contacts/imagecomm_register.php"]; NSLog(post); NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

connection release method in connectionDidFinishLoading, causes error

点点圈 提交于 2019-12-25 07:29:30
问题 testing request and getting the response example in official apple developer site. https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html using [connection release] method in connectionDidFinishLoading, causes error :Should've been invalidated - EXC_BAD_ACCESS if I comment line [connection release] method; everything seems working but Im afraid there is memory leak occurs because of non existent release of connection. what may

Failed To Send Json With NSUrlconnection

丶灬走出姿态 提交于 2019-12-25 06:48:12
问题 i am implementing this code wich take apple in app purchase receipt from the current transaction (not listed here) i am converting it to base64 NSData object, create new NSString with the values and keys (json object) and send it trough NSUrlconnection . when the compiler hits the init with request the app crashes after 2 seconeds... without to get any response. this is the code. NSData *data = [NSData dataFromBase64String:receiptStr]; NSString *jsonString = [NSString stringWithFormat:@"{\

Upload and download data from server with Cocoa Touch?

笑着哭i 提交于 2019-12-25 04:24:55
问题 How can I upload/download data from a server in Cocoa Touch. Here's what I have so far... -(void)uploadSchedule:(id)sender { NSData *content = [NSData dataWithContentsOfFile:self.dataFilePath]; NSString *stuff = [[NSString alloc] initWithData:content encoding:NSASCIIStringEncoding]; NSURL *url = [NSURL URLWithString:@"http://thetis.lunarmania.com"]; NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc]initWithURL:url]; [urlRequest setHTTPMethod:@"POST"]; [urlRequest setHTTPBody: