Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I use NSCachedURLResponse,I got "301PermMove"

when I test NSURLCache,I got "301PermMove",this is my code

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

NSURL *url = [NSURL URLWithString:@"https://www.github.com"];
NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10];
NSURLCache *shareCache = [NSURLCache sharedURLCache];
NSCachedURLResponse *resp = [shareCache cachedResponseForRequest:urlRequest];
NSLog(@"cache data:%@",[[NSString alloc]initWithData:resp.data encoding:NSUTF8StringEncoding]);

[NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {

    NSLog(@"data:%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
}];
}

first touch: cache data is nil ,and second touch:cache data is 301PermMove . And why? I don't know.

like image 448
hmxxxhhh Avatar asked Oct 30 '22 13:10

hmxxxhhh


1 Answers

You are getting a HTTP response status code 301 Moved Permanently. That means that the resource you are looking for was moved to another location. For me was very easy because the problem was the old URL changed from http to https. Unfortunately I don't have the answer to your question but you can try to accessing to an URL without redirection.

Hope this can help.

like image 170
elderio Avatar answered Nov 08 '22 06:11

elderio