ios 当我使用NSCachedURLResponse时,我得到了“301PermMove”

cfh9epnr  于 2023-05-30  发布在  iOS
关注(0)|答案(1)|浏览(123)

当我测试NSURLCache时,我得到了“301PermMove”,这是我的代码

-(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]);
}];
}

第一次触摸:cache data为nil,second touch:cache data为301PermMove。为什么?我不知道。

voj3qocg

voj3qocg1#

HTTP响应状态码301 Moved Permanently这意味着您正在寻找的资源已被移动到另一个位置。对我来说很容易,因为问题是旧的URL从http改为https。不幸的是,我没有你的问题的答案,但你可以尝试访问一个网址没有重定向。
希望这能有所帮助。

相关问题