@nicael and @Shadow Wizard are right in their explanation. However, put simply I wanted to retrieve a search page (in its mobile version) with a single request, inside a Cocoa Webview (no post-processing, no js, no nothing).
So, I looked into the HTTP headers AFTER setting the mobile view. And noticed an interesting thing : When Mobile mode is on, we are packing a theme
cookie with the value 2
. (While, for the "Full Site" mode, theme
is set to 0
).
And that's how I came up to the following very simple code, in Objective-C/Cocoa :
- (void)mobileSearchSO:(NSString *)searchFor
{
// Format the search path
NSString* searchPath = [NSString stringWithFormat:@"http://stackoverflow.com/search?q=%@",searchFor];
NSURL* searchUrl = [[NSURL alloc] initWithString:searchPath];
// Create the request
NSMutableRequest* req = [NSMutableURLRequest requestWithURL:searchUrl];
// Create the cookie
NSHTTPCookie* cookie = [NSHTTPCookie cookieWithProperties:@{
NSHTTPCookieDomain : @"stackoverflow.com",
NSHTTPCookiePath : @"/",
NSHTTPCookieName : @"theme",
NSHTTPCookieValue : @"2"
}];
// Set the cookie
[req setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:@[cookie]]];
// Load the request
[[_webView mainFrame] loadRequest:req];
}
Tested and working fine. Enjoy! :-)
/search
- live preview