Nsurlrequest with useragent

Source: Internet
Author: User

About the HTTP request on iOS is still learning, from the earlier time found that the original iOS HTTP request can automatically save cookies to later, found that ASIHTTPRequest will have user-agent, To now find unexpectedly nsurlrequest default without user-agent. To add a method:

#define UserAgent @ "mozilla/5.0 (iPhone; CPU iPhone os 5_1_1 like Mac os X applewebkit/534.46 (khtml, like Gecko) version/5.1 mobile/9b206 safari/7534.48.3 "
Nsmutableurlrequest *restrequest = [Nsmutableurlrequest requestwithurl:url
Cachepolicy:nsurlrequestreloadignoringcachedata
timeoutinterval:30.0];
[Restrequest setvalue:useragent forhttpheaderfield:@ "User-agent"];

And my situation is a little bit more complicated, I found that the server to the URL I requested unexpectedly jump, but also need to implement a proxy:

-(Nsurlrequest *) connection: (nsurlconnection*) connection
Willsendrequest: (nsurlrequest*) Request
Redirectresponse: (nsurlresponse*) redirectresponse{
Nsmutableurlrequest *newreq = [request mutablecopy];
[Newreq setvalue:useragent forhttpheaderfield:@ "User-agent"];
return [Newreq autorelease];
}

That ' s all

Resources:
Nsmutableurlrequest and User-agents

turn: transfer from Rainbird's personal blog

Nsurlrequest with useragent

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.