昨天,我在使用我的应用程序时发现了一个bug,当我试图下载一个AGPS文件并更新我的自行车计算机以便更快地定位。AGPS号码不能下载。
下面的步骤是我检查错误的方法。
你的连接不是私人的 攻击者可能试图从alp.u-blox.com窃取您的信息(例如密码、消息或信用卡)。NET::ERR_CERT_DATE_INVALID 自动发送一些系统信息和页面内容到谷歌,以帮助检测危险的应用程序和网站。隐私政策
然后我使用Charles捕获应用程序请求,它显示了url请求被更改为:
https://alp.u-blox.com/current_14d.alp
-- http changed to https
有人说问题在于iOS10强制所有http请求使用https。因此,我在我的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。为什么?!!
任何帮助都是感激的,提前感谢。
发布于 2017-08-02 09:51:24
让我解释一下NSAllowsArbitraryLoads
到底做了什么。由于iOS 9,没有NSAllowsArbitraryLoads
的应用程序或显式地将NSAllowsArbitraryLoads
设置为false
(默认值)将阻止以下URL:
不要在生产环境中将其设置为true
,App将要求将其设置为true
的理由。只允许使用NSExceptionDomains
的必要域。
默认情况下,AFNetworking
也会阻止证书无效的HTTPS。为了解决这个问题,应该使用有效的证书(必须始终保持所有证书的有效性和安全性),或者在文件头处使用以下代码:
#ifdef DEBUG
#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
#endif
相关Github提交这里
对于你的问题,以下是答案:
这是由web服务器完成的,而不是应用程序本身。
它似乎检查用户代理。请通过更改用户代理和重试反复检查(提示:最简单的方法是使用HTTP客户端Chrome扩展/ Firefox Addon进行测试)
与问题2相同的答复
希望能帮上忙。
https://stackoverflow.com/questions/45454639
复制相似问题