昨天,我在使用我的应用程序时发现了一个错误,当我尝试下载AGPS文件并更新我的自行车电脑以便更快地定位时。 AGPS不能下载。
以下步骤是我检查错误的方法。
您的连接不是私密的
攻击者可能试图从alp.u-blox.com窃取您的信息(例如,密码,邮件或信用卡)。 NET :: ERR_CERT_DATE_INVALID
自动向Google发送一些系统信息和页面内容,以帮助检测危险的应用和网站。隐私政策
然后我使用Charles捕获应用程序请求,它显示我确实将请求更改为:
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];
我的问题
我做的更多
我从服务器获取文件并将其上传到文件主机服务器:https://www.qiniu.com/,复制文件地址如下:
http://okzqhpqwj.bkt.clouddn.com/current_14d.alp
将url放入代码中,一切都很好,请求不会更改为https。为什么?? !!
感谢任何帮助,提前谢谢。
答案 0 :(得分:0)
让我解释一下NSAllowsArbitraryLoads
的真正含义。自iOS 9起,没有NSAllowsArbitraryLoads
或明确将NSAllowsArbitraryLoads
设置为false
(默认值)的应用会阻止以下网址:
请勿在生产环境中将其设置为true
,并且应用审核会要求将其设置为true
的理由。仅允许使用NSExceptionDomains
的必要域名。
默认情况下,AFNetworking
也会阻止包含无效证书的HTTPS。要解决此问题,您应该使用有效的证书(始终保持所有证书有效且安全),或者在文件的标题处使用以下代码:
#ifdef DEBUG
#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
#endif
相关Github提交here
对于您的问题,以下是答案:
由网络服务器完成,而不是应用程序本身。
它似乎检查用户代理。请通过更改用户代理进行仔细检查并重试(提示:最简单的方法是使用HTTP客户端Chrome扩展程序/ Firefox插件进行测试)
与问题2相同的答案
希望它有所帮助。