求助贴 哪位大大能知道下UIWebView设置代理服务器(Proxy)呢,获取视频的URL
最近公司想要做个浏览器,浏览器主要是为了统计用户访问地址,希望用户的访问走代理服务器,从而分配用户合理的资源
然而国内并没有太好的方案,倒是在论坛看到了使用AFNetworking设置Web的网络代理了(传送门http://stackoverflow.com/questions/28361357/handling-redirects-with-custom-nsurlprotocol-and-http-proxy),主要代码如下:
/**
* 配置代理的一些信息
*/
- (NSURLSessionConfiguration *)setProxyWithConfiger {
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
config.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
config.connectionProxyDictionary = [self setProxyDictWithCFHTTPStream];
return config;
}
/**
* 配置代理属性
*
* 使用的是 CFHTTPStream.h 的一些属性,但是不支持 enale, 采用 NSString 方式填写
*
* enable属性是否可以采用kCFNetworkProxiesHTTPEnable代替,但是 HTTPS 不支持
*
* @return 属性配置字典
*/
- (NSDictionary *)setProxyDictWithCFHTTPStream {
NSString *ip = [[NSUserDefaults standardUserDefaults] stringForKey:@"ipString"];
NSString *port = [[NSUserDefaults standardUserDefaults] stringForKey:@"portString"];
NSInteger portInt = [port integerValue];
NSDictionary *dict = @{
@"HTTPEnable" : @YES,
(id)kCFStreamPropertyHTTPProxyHost:ip,
(id)kCFStreamPropertyHTTPProxyPort:@(portInt),
@"HTTPSEnable" : @YES,
(id)kCFStreamPropertyHTTPSProxyHost:ip,
(id)kCFStreamPropertyHTTPSProxyPort:@(portInt)
};
NSLog(@"setProxyDictWithCFHTTPStream----%@",dict);
return dict;
}
但是以上方法只是在首次load时候走代理,再次加载则是走的系统的请求,在UIWebViewDelegate的代理方法shouldStartLoadWithRequest中过滤下内容,再次进行请求
if (navigationType == UIWebViewNavigationTypeLinkClicked || navigationType == UIWebViewNavigationTypeFormSubmitted || navigationType == UIWebViewNavigationTypeFormResubmitted
|| navigationType == UIWebViewNavigationTypeReload || navigationType == UIWebViewNavigationTypeBackForward) {
[self loadURL:[request URL]];
return NO;
}
return YES;,结果是不能获取到播放视频的东西包,抓包失败了,不知道如何抓到视频的url呢。。求助啊~