Wednesday, May 1, 2013

NSMutableURLRequest setMainDocumentURL example ios


Sets the main document URL for the receiver.
- (void)setMainDocumentURL:(NSURL *)theURL
Parameters of [NSMutableURLRequest setMainDocumentURL]
The new main document URL. Can be nil.
Discussion of [NSMutableURLRequest setMainDocumentURL]
The caller should set the main document URL to an appropriate main document, if known. For example, when loading a web page the URL of the HTML document for the top-level frame would be appropriate. This URL will be used for the “only from same domain as main document” cookie accept policy.
Example of [NSMutableURLRequest setMainDocumentURL]
NSURL *url = [NSURL URLWithString:@"" relativeToURL:[NSURL URLWithString:@""]];
    NSMutableURLRequest *request = nil;

        request = [NSMutableURLRequest requestWithURL:url];

    NSArray * availableCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:@""]];
    NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies:availableCookies];
        [request setHTTPShouldHandleCookies:YES];
        [request setMainDocumentURL:[NSURL URLWithString:@""]];
        [request setAllHTTPHeaderFields:headers];//
        [mWebView loadRequest:request];