nsurlrequest

Does NSURLConnection take advantage of NSURLCache?

天涯浪子 提交于 2019-12-30 00:35:53
问题 I'm trying to figure out how to use the URL loading framework to load URLs taking advantage of caching. I am using NSURLConnections and feeding them NSURLRequests. I have even set the cachePolicy on those requests to NSURLRequestReturnCacheDataElseLoad. The first time I load a request, it does automatically get put in the cache ( [NSURLCache sharedCache] has it). But the next time I load the same request, the NSURLConnection seems to ignore what's in the cache and reload the data. Am I

Send custom headers with UIWebView loadRequest

筅森魡賤 提交于 2019-12-29 14:28:55
问题 I want to be able to send some extra headers with my UIWebView loadRequest method. I have tried: NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.reliply.org/tools/requestheaders.php"]]; [req addValue:@"hello" forHTTPHeaderField:@"aHeader"]; [self.theWebView loadRequest:req]; I have also tried subclassing the UIWebView and intercepting the - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:

Reliable way to compare two NSURL or one NSURL and an NSString?

让人想犯罪 __ 提交于 2019-12-28 11:47:06
问题 I recently had a problem when comparing two NSURLs and compare one NSURL with an NSString(which is a URL address), the situation is I got an NSURLRequest from somewhere, I may or may not know the URL address it points to, and I have an URL NSString, say "http://m.google.com", now I need to check if the URL in that NSURLRequest is the same as the URL string I had: [[request.URL.absoluteString lowercaseString] isEqualToString: [self.myAddress lowercaseString]]; this returns NO as the

Add HTTP Header to NSURLRequest

房东的猫 提交于 2019-12-28 03:30:06
问题 Is there any way to add HTTP header to NSURLRequest object? I used to add them in NSMutableURLRequest using: [request addValue:@"PC" forHTTPHeaderField:@"machineName"] 回答1: I don't think you can modify the HTTP Headers of a NSURLRequest . I think you're trying to modify a NSURLRequest object that you didn't initialize? You could create a mutableCopy of your request and then set the header fields with the following method: -(void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field.

Multiple asynchronous URL requests

被刻印的时光 ゝ 提交于 2019-12-25 12:43:20
问题 My iPhone application has been "lagging" or rather "frozen" when it got past the start up screen. I think this is due to the registration for remote push notifications is send as a synchronous request and therefore I would like to change this to asynchronous. This is a problem since I am already sending one asynchronous request for retrieving some data and save it to the phone. So, I would like to send both of these requests asynchronously and have them do two different things in - (void

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:@"{\

Local HTML Cache policy in UIWebView

依然范特西╮ 提交于 2019-12-25 05:32:47
问题 I have walked through various solution to clear the local image cache in UIWebView, while i trying to load the image in html it atomically displays the previous image(i using the same name to replace the image in template). [[NSURLCache sharedURLCache] removeAllCachedResponses]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL fileURLWithPath:[[CustomFunctions getFilesPath] stringByAppendingPathComponent:obj]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData

NSURLConnection Asyncronous Request returns null

人盡茶涼 提交于 2019-12-24 19:33:53
问题 Followed a recently made YouTube tutorial try connecting to web address asynchronously. Retuning null for the response, but the data length is greater than 0. I've seen other code that does both null & length checking, which I didn't throw, just NSLog'd them. @implementation ViewController -(void)fetchAddress:(NSString *)address { NSLog(@"Loading Address: %@", address); [iOSRequest requestToPath:address onCompletion:^(NSString *result, NSError *error) { dispatch_async(dispatch_get_main_queue(

how to verify the identity of the client from the server?

泪湿孤枕 提交于 2019-12-24 19:02:14
问题 I am using Rails as my server of an iOS application. Currently, from the App, it launches an URL request for a web page from the server to get the data. My question is, how can I guarantee that only my App can access the server, one can't get anything from the clients/apps/browsers from my server? 回答1: I don't use Rails for my Server, i use PHP. But I think the approach is the same. Add a sort of a key to your Request. I do it always as a POST value. Hardcode this key in your application. In

How to get NSDictionary from NSURLSessionDataTask

风流意气都作罢 提交于 2019-12-24 18:06:07
问题 -(NSDictionary *)fetchFromUrl:(NSString *)url{ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { dataFetched = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]; }]; [task resume]; NSLog(@"dataFetched, %@", dataFetched); return dataFetched; } So I