Tag: nsurlconnection

NSURLConnection / NSURLRequest gzip支持

有谁知道NSURLConnection / NSURLRequest是否支持gzip请求。 如果有,你能提供更多的信息吗? 提前致谢!

NSURLConnection和大中央调度

build议在gcd样式块中包装NSUrlConnection并在low_priority队列上运行它? 我需要确保我的连接没有发生在主线程上,连接需要是asynchronous的。 我还需要同时发出几个请求。 如果我去gcd路线,我不知道哪个线程的NSUrlConnectionDelegate方法被调用。 NSURLConnection依赖委托,所以一旦连接完成,无论处理它的包装类将需要调用其调用者。 我不确定如何处理连接工作启动/结束时调用的所有各种callback: – (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)response; – (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)incrementalData; – (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error; – (void)connectionDidFinishLoading:(NSURLConnection *)connection; 我应该只是调用同步版本,但包裹在gcd块? 如果我想取消呼叫,请使用'dispatch_suspend'? dispatch_async(queue,^{ NSString* result = [self mySynchronousHttp:someURLToInvoke]; }); // If I need to cancel dispatch_suspend(queue);

从后台线程到服务器的asynchronous请求

当我试图从后台线程对服务器执行asynchronous请求时,我遇到了这个问题。 我从来没有得到这些要求的结果。 显示问题的简单例子: @protocol AsyncImgRequestDelegate -(void) imageDownloadDidFinish:(UIImage*) img; @end @interface AsyncImgRequest : NSObject { NSMutableData* receivedData; id<AsyncImgRequestDelegate> delegate; } @property (nonatomic,retain) id<AsyncImgRequestDelegate> delegate; -(void) downloadImage:(NSString*) url ; @end @implementation AsyncImgRequest -(void) downloadImage:(NSString*) url { NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { receivedData=[[NSMutableData data] retain]; } else { } […]

NSURLSession:如何增加URL请求的超时时间?

我正在使用iOS 7的新的NSURLSessionDataTask检索数据如下: NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest: request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { // }]; 如何增加超时值以避免错误"The request timed out" (在NSURLErrorDomain代码= -1001 )? 我已经检查了NSURLSessionConfiguration的文档,但没有find设置超时值的方法。 感谢您的帮助!

如何在iOS中处理“CFNetwork SSLHandshake失败”

有些时候,我得到CFNetwork SSLHandshake failed -(9806)在我的代码,但我不知道为什么这是发生,因为我的代码运行顺利,除了当我运行它在iOS 6,然后在iOS 7 64位我得到这个警告。 有人可以build议我,如何处理这个问题?

不调用NSURLConnection委托方法

我正在尝试创build一个简单的NSURLConnection与使用GET请求的服务器进行通信。 连接工作正常,但委托NSURLConnection的方法永远不会被调用.. 这是在做什么: NSString *post = [NSString stringWithFormat:@"key1=%@&key2=%@&key3=%f&key4=%@", val1, val4, val3, val4]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease] ; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.domain.com/demo/name/file.php?%@", post]]]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection start]; 已经实现了下面的委托方法,但是没有一个被调用 -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ NSLog(@"did fail"); } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ NSLog(@"did receive data"); } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ NSLog(@"did […]

资源无法加载,因为应用传输安全策略需要使用安全连接

当我将Xcode更新到7.0或iOS 9.0时,我正面临着这个问题。 不知何故,它开始给我的标题错误 “由于App Transport安全策略要求使用安全连接,因此无法加载资源” Webservice方法: -(void)ServiceCall:(NSString*)ServiceName :(NSString *)DataString { NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; [sessionConfiguration setAllowsCellularAccess:YES]; [sessionConfiguration setHTTPAdditionalHeaders:@{ @"Accept" : @"application/json" }]; NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",ServiceURL]]; NSLog(@"URl %@%@",url,DataString); // Configure the Request NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setValue:[NSString stringWithFormat:@"%@=%@", strSessName, strSessVal] forHTTPHeaderField:@"Cookie"]; request.HTTPBody = [DataString dataUsingEncoding:NSUTF8StringEncoding]; […]

NSURLConnection sendAsynchronousRequest:queue:completionHandler:在一行中发出多个请求?

我一直在使用NSURLConnection's sendAsynchronousRequest:queue:completionHandler:方法非常棒。 但是,我现在需要连续发出多个请求。 我仍然在使用这个很好的asynchronous方法的时候怎么能这样做呢?

POST请求不考虑NSMutableURLRequest超时间隔

我有以下问题。 在使用HTTP方法POST的NSMutableURLRequest ,为连接设置的超时间隔被忽略。 如果互联网连接有问题(代理错误,错误的DNS),约2-4分钟后url请求失败,但NSLocalizedDescription = "timed out";不会NSLocalizedDescription = "timed out"; NSUnderlyingError = Error Domain=kCFErrorDomainCFNetwork Code=-1001 UserInfo=0x139580 "The request timed out. 如果使用的http方法是GET它工作正常。 通过https连接是async 。 NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setTimeoutInterval:10]; //Set the request method to post [request setHTTPMethod:@"POST"]; if (body != nil) { [request setHTTPBody:body]; } // Add general parameters […]

如何发送asynchronousURL请求?

我想知道如何获得一个返回值1或0只是…从一个URL请求asynchronous返回。 目前我是这样做的: 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(@"check Value %@",checkValue); 这工作,但是它阻止我的主线程,直到我从URL的回复,我如何设置它,这样做会在另一个线程,而不是主线程? 编辑:答案我结束upcalling我的function,这个效果不错:) [self performSelectorInBackground:@selector(shouldCheckForUpdate) withObject:nil];