昨天,我在使用我的应用时发现了一个错误,当我尝试下载AGPS文件并更新我的自行车电脑以便更快地定位时。 AGPS cound不能下载。iOS10 http请求成为https请求,但有一些不是
- AGPS文件网址是:http://alp.u-blox.com/current_14d.alp
- 的iOS系统版本:iOS版10.3.2
- 网络:WIFI和移动网络的4G以下
步骤是我做检查的bug。
- 检查Safari上的AGPS文件(在我的Macbook Pro上),它可以成功下载。
- 在Chrome中打开的AGPS文件的URL,但不能下载,它让我看到:
您的连线不是私人
攻击者可能会试图从alp.u-窃取你的信息blox.com(例如,密码,消息或信用卡)。 NET :: ERR_CERT_DATE_INVALID
自动将一些系统信息和页面内容发送给Google,以帮助检测危险的应用程序和网站。隐私政策
- 在我的Android手机浏览器上打开AGPS URL,下载文件成功。
- 在我的iPhone Safari上打开AGPS URL,无法打开网页。
然后我捕捉使用查尔斯的应用要求,它让我看到真正的URL请求变更为:
https://alp.u-blox.com/current_14d.alp
-- http changed to https
有人说这个问题是因为iOS10的强制使用HTTPS所有HTTP请求。所以我在Info.plist上添加了一些设置。
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<key>sina.com.cn</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
或类似这样的
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<key>twitter.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
然后再捕捉要求,既没有工作。
网络要求如下代码:
@property (nonatomic, strong) AFHTTPSessionManager *sessionManager;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSURLSessionDownloadTask *downloadTask = [self.sessionManager
downloadTaskWithRequest:request
progress:^(NSProgress *_Nonnull downloadProgress) {
if (progressBlock) {
progressBlock((int64_t)downloadProgress.completedUnitCount, downloadProgress.totalUnitCount);
}
}
destination:^NSURL *_Nonnull (NSURL *_Nonnull targetPath, NSURLResponse *_Nonnull response) {
NSString *otaFilePath = [NSString stringWithFormat:@"%@/%@", kOTA_FIRMWARE_DOWNLOAD_DIR, [response suggestedFilename]];
return [NSURL fileURLWithPath:otaFilePath];
}
completionHandler:^(NSURLResponse *_Nonnull response, NSURL *_Nullable filePath, NSError *_Nullable error) {
if (error) {
xLog_error(@"[Error] 下载固件失败, Error Message: %@", error.localizedDescription);
completeHandler(NO, nil);
} else {
completeHandler(YES, filePath.path);
}
}];
[downloadTask resume];
请求由NSURLSession也不能正常工作。
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"cache-control": @"no-cache",
@"postman-token": @"aa15f00a-bc58-082a-c8e3-e636537b7fa7" };
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL
URLWithString:@"http://alp.u-blox.com/current_14d.alp"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
我的问题
- 不iOS10改变从http网址为https?或由网络服务器更改?
- 为什么url可以通过Safari(在PC上)打开,并且无法在Safari上打开(在iPhone上)?
- 为什么可以在Android上打开?
更多我做什么
我从服务器获取的文件,并将其上传到一个文件中主机服务器:
http://okzqhpqwj.bkt.clouddn.com/current_14d.alp
将网址放入代码中,一切都很好,请求不会更改为https。为什么??!!
任何帮助感谢,提前感谢。
首先,如何使用iOS10发送http请求... –
HTTP到HTTPS的转发由Web服务器完成,与应用程序本身无关。另外,为什么要标签Android?最后,请向我们展示您编写的下载代码。 – Raptor
谢谢你,猛禽。我也测试Android版本的应用程序,请求相同的网址,并正常工作。 Android版本7.0。这也是一个我不能理解的问题,如果同一个网址,为什么Android可以访问,但iOS10.0不能。 Android安全级别不同? –