怎么修改 User-Agent里面的内容
1个回答
展开全部
一种是
change-user-agent-in-uiwebview-iphone-sdk
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)navigationType {
NSMutableURLRequest *request = (NSMutableURLRequest *)req;
if ([request respondsToSelector:@selector(setValue:forHTTPHeaderField:)]) {
[request setValue:[NSString stringWithFormat:@"%@ Safari/528.16", [request valueForHTTPHeaderField:@"User-Agent"]] forHTTPHeaderField:@"User_Agent"];
}
return YES;
}
另一种是调用私有API
NSString *userAgent = @"Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_1 like Mac OS X;ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F136 Safari/525.20";
id webDocumentView;
id webView;
webDocumentView = objc_msgSend(myWebView, @selector(_documentView));
object_getInstanceVariable(webDocumentView, "_webView", (void**)&webView);
objc_msgSend(webView, @selector(setCustomUserAgent:), userAgent);
但是貌似两种方法都不起作用,不论在iphone上怎么修改,服务器端读到的User-Agent总是默认的值
如果读取是用User-Agent,写入是User_Agnet的话,好像也不起作用。
change-user-agent-in-uiwebview-iphone-sdk
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)navigationType {
NSMutableURLRequest *request = (NSMutableURLRequest *)req;
if ([request respondsToSelector:@selector(setValue:forHTTPHeaderField:)]) {
[request setValue:[NSString stringWithFormat:@"%@ Safari/528.16", [request valueForHTTPHeaderField:@"User-Agent"]] forHTTPHeaderField:@"User_Agent"];
}
return YES;
}
另一种是调用私有API
NSString *userAgent = @"Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_1 like Mac OS X;ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F136 Safari/525.20";
id webDocumentView;
id webView;
webDocumentView = objc_msgSend(myWebView, @selector(_documentView));
object_getInstanceVariable(webDocumentView, "_webView", (void**)&webView);
objc_msgSend(webView, @selector(setCustomUserAgent:), userAgent);
但是貌似两种方法都不起作用,不论在iphone上怎么修改,服务器端读到的User-Agent总是默认的值
如果读取是用User-Agent,写入是User_Agnet的话,好像也不起作用。
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询