Tag: nsurlconnection

有没有办法将参数的NSDictionary附加到NSURLRequest而不是手动创build一个string?

AFNetworking允许你添加一个参数的NSDictionary到一个请求,并将它附加到请求。 所以,如果我想要做一个GET请求?q=8&home=8888我只是简单地做一个NSDictionary,比如@{@"q": @"8", @"home": @"8888"} 。 有没有办法做到NSURLSession / NSURLConnection / NSURLRequest ? 我知道我可以使用NSJSONSerialization来附加JSON数据,但是如果我只是希望它们作为GET参数在URL中呢? 我应该只是添加一个类别?

iOS和SSL:无法validation自签名服务器证书

我对使用SSL通道使用Web服务相当陌生。 经过相当不错的search后,我发现了一种使用NSURLConnection委托API来执行SSL / HTTPS身份validation的方法。 以下是执行实际身份validation的代码片段: – (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { [self printLogToConsole:@"Authenticating…."]; [self printLogToConsole:[NSString stringWithFormat:@"\n%@\n", [challenge description]]]; NSLog(@"\n\nserverTrust: %@\n", [[challenge protectionSpace] serverTrust]); /* Extract the server certificate for trust validation */ NSURLProtectionSpace *protectionSpace = [challenge protectionSpace]; assert(protectionSpace); SecTrustRef trust = [protectionSpace serverTrust]; assert(trust); CFRetain(trust); // Make sure this thing stays around until we're done […]

NSURLErrorDomain错误-1012

我需要parsing密码保护的URL的XML文件我试着下面 NSURLCredential *credential = [NSURLCredential credentialWithUser:@"admin" password:@"123456" persistence:NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"xyz.com" port:80 protocol:@"http" realm:nil authenticationMethod:NSURLAuthenticationMethodDefault]; [[NSURLCredentialStorage sharedCredentialStorage] setCredential:credential forProtectionSpace:protectionSpace]; url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; NSURLResponse *response; NSError *error; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse: &response error: &error]; […]

加载NSData到UIWebView

在我的网页浏览器,我想加载一个UIWebView NSURLConnection NSData获得。 当我尝试加载到UIWebView ,而不是该网站,它出现了HTML纯文本。 这是我的代码: 在viewDidLoad: NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.msn.com"]]; [NSURLConnection connectionWithRequest: request delegate:self]; 后来在代码中: -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { webdata = [NSMutableData dataWithData: data]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { [webview loadData:webdata MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil]; }

iphone:安全restfull服务器“此服务器的证书无效

我正在尝试使用安全的宁静的服务,这给了错误 错误=错误域= NSURLErrorDomain代码= -1202“此服务器的证书无效,您可能正在连接假装为”xxx.xxx.xxx.xxx“的服务器,这可能会将您的机密信息置于危险之中。 在xCode 4.2上工作,在哪里错误或缺less任何步骤。 使用下面的代码 RegisterUser.f @interface RegisterUser : UIViewController<UITextFieldDelegate, UIScrollViewDelegate, NSURLConnectionDelegate> RegisterUser.m – (IBAction)SubmitBtnAction:(id)sender { NSURL *url = [NSURL URLWithString:@"https://xx.xx.xx.xxx:8223/jaxrs/tunedoorgateway/getCountries"]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:urlRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if ([data length] >0 && error == nil) { NSLog(@"Data = %@", data); // DO […]

对于分块传输编码,NSURLConnection是什么select

我已经检查了与此相关的其他问题,但唯一的答案是“使用ASIHTTPRequest ”,因为这不再被开发,我想问一下人们正在使用什么替代品,同时在我们的SDK上工作,我遇到了很多奇怪的行为在NSURLConnection从服务器接收数据时。 我们追踪到NSURLConnection在分块编码方面不能很好地处理响应。 或者至less是这样,我们在这里读到NSURLConnection和“chunked”转码 我们正在谈论的一些开发者说,在iOS 5中它变得更好,我们需要确保我们的SDK至less与iOS 4.3向后兼容。 我想确认这在NSURLConnection是一个问题,人们是如何处理它的。 到目前为止,我发现的所有替代方法都是基于NSURLConnection ,我假设这样做也会有相同的缺陷。 ASIHTTPRequest事实上起作用,因为它的基础比NSURLConnection稍微低一点,但是正在寻找不再支持的知识的替代品。 其他库的列表是: Restkit , ShareKit , LRResty , AFNetworking , TTURLRequest 我知道这里也有类似的问题RESTkit是ASIHTTPRequest的一个很好的替代品吗? 这里ASIHTTPRequest替代scheme但是这两个解决scheme都基于NSURLConnection。 编辑:我注意到我在我的post开始时指出了错误的问题,所以更新。 它指向2008年的一个线程,我看过类似的,但没有最近。

iOS上的NSURLConnection不会尝试caching大于50KB的对象

尽pipe苹果的文档指出 ,iOS上的NSURLCache根本不做任何磁盘(闪存)caching。 您可以NSURLCache子类,以更改获取和存储操作的行为来使用磁盘(就像SDURLCache一样),但是由于以下严重的caching使用和实现限制, d期望: NSURLConnection甚至不会调用storeCachedResponse:forRequest:对于超过大约50KB( storeCachedResponse:forRequest:是storeCachedResponse:forRequest: 52428字节)的文件。 这使得NSURLCache我们的使用(200KB图像)毫无意义,因为它甚至不会进入caching。 因此,我们必须手动添加高于NSURLConnection的级别的caching。 即使手动调用NSURLCache的内置storeCachedResponse:forRequest:如果响应小于180KB,它只会将响应存储在内存中。 我通过手动调用storeCachedResponse来testing这个,并且看到currentMemoryUsage之前/之后的数据长度在大约180KB以上没有改变。 所以我们也必须编写自己的LRU内存caching。 有没有人注意到这些问题? 还是有什么我失踪? 仅供参考,我在模拟器和iPad 2上运行iOS 4.3。

如何取消使用NSURLConnection的持久连接?

是否有可能摧毁已经创buildNSURLConnection的持久连接? 我需要能够销毁持久连接,并执行另一个SSL握手。 就像现在一样,调用[conn cancel]会留下一个持久的连接,这个连接被用于下一个连接请求,这个连接请求我不想发生。

未调用NSURLConnection didReceiveData

我已经阅读了大量的消息,再次说同样的事情:当你使用NSURLConnection,委托方法不被调用 。 我明白,苹果的文件是不完整的,并引用不赞成的方法,这是一个耻辱,但我似乎无法find一个解决scheme。 请求的代码在那里: // Create request NSURL *urlObj = [NSURL URLWithString:url]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlObj cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"]; if (![NSURLConnection canHandleRequest:request]) { NSLog(@"Can't handle request…"); return; } // Start connection dispatch_async(dispatch_get_main_queue(), ^{ self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; // Edited }); …代表方法的代码在这里: – (void) connection:(NSURLConnection *)_connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"Receiving […]

NSURLConnection委托方法

我很难findNSURLConnection委托方法实现的任何示例。 我想用一个button点击一个HTTPpost发送数据。 不知道如何使“提交”屏幕和“提交”。 (我知道如何使用微调,并将使用它们) 我正在使用此代码根据botton单击操作,但无法使用任何代表的东西。 不知道如何实现他们与我目前的设置。 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://myURL.com"]]; [request setHTTPMethod:@"POST"]; NSString *postString = [wait stringByAppendingString:co]; [request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"]; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; //[[NSURLConnection alloc] initWithRequest:request delegate:self]; [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; [SVProgressHUD dismissWithSuccess:@"Submission Successful"];