How iOS adds an HTTP request header for a custom UIWebView

Source: Internet
Author: User

Method One: You have two options to create at the beginning of the nsmutableurlrequest and load, with Web view loadreqest or take over your application with Nsurlprotocol full URL loaded.

The easiest way to do this is to have the first choice of code as its only extra line: (validated)

-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) navigationtype
{
    nsmutableurlrequest *mutablerequest = [request mutablecopy];
    
    NSString *sendparam = [[NSString alloc] InitWithData:mutableRequest.HTTPBody encoding:nsutf8stringencoding];
    
    if (![ Sendparam isequaltostring:@ ""]) {
        
        NSString *newdata = [Sendparam md5value];
        
        Nsuinteger length = [NewData length];
        
        [Mutablerequest addvalue:[nsstring stringwithformat:@ "%ld", length] forhttpheaderfield:@ "felength"];
        
        request = [mutablerequest copy];
        
    } else{return
        
        YES
    }
    
    [Self.webview loadrequest:request];

    Return YES
}

Method Two: Choose to use Nsurlprotocol to take over you this involves registering your own solution, using the URL of the application to create a specific class to load. The main method of rewriting is canonicalrequestforrequest.

I suggest you take a look at both tutorials Nsnipster and Raywenderlich for the guide. (not validated)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.