来自 tumblr 的 iOS 和 OS X 上的网络连接库:JXHTTP
JXHTTP 是来自 tumblr 的 iOS 和 OS X 上的网络连接库。它利用操作队列和GCD对Cocoa的内置NSURLConnection对象提供了强大的包装,加入许多有用的功能如:块响应对象和跨越多个请求过程跟踪。它致力于成为尽可能轻量级和可读性,使它更易于使用或自定义高级的行为。
示例
Asynchronous
JXHTTPOperation *op = [JXHTTPOperation withURLString:@"https://encrypted.google.com/"]; op.didFinishLoadingBlock = ^(JXHTTPOperation *op) { NSLog(@"%@", op.responseString); }; [[JXHTTPOperationQueue sharedQueue] addOperation:op];
Synchronous
JXHTTPOperation *op = [JXHTTPOperation withURLString:@"https://encrypted.google.com/"]; [op startAndWaitUntilFinished]; NSLog(@"%@", op.responseString);
Complex
NSURL *postURL = [NSURL URLWithString:@"https://web.site/api/POST"]; NSDictionary *postParams = @{ @"make": @"Ferrari", @"model": @"458 Italia" }; JXHTTPOperation *op = [[JXHTTPOperation alloc] initWithURL:postURL]; op.requestBody = [[JXHTTPFormEncodedBody alloc] initWithDictionary:postParams]; op.requestCachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData; op.responseDataFilePath = @"/tmp/downloaded_data"; op.trustedHosts = @[ postURL.host ]; op.performsBlocksOnMainQueue = YES; op.didSendDataBlock = ^(JXHTTPOperation *op) { NSLog(@"%lld bytes uploaded so far", op.bytesUploaded); }; [[JXHTTPOperationQueue sharedQueue] addOperation:op];
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!