• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Setting the NSURLDownload user agent
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting the NSURLDownload user agent


  • Subject: Setting the NSURLDownload user agent
  • From: Nick Beadman <email@hidden>
  • Date: Fri, 17 Apr 2015 14:23:17 -0700

I have a WebKit application which uses -[WebView setCustomUserAgent:] to set the user agent for the browser portion. I register certain URL schemes and then use NSURLDownload to download files from the server. So far so good.

What I have found is that if you create an NSURLDownload with NSURLRequest then the user-agent for an http download is set to something like:

MyApplicationName/CFBundleVersion CFNetwork/720.3.13 Darwin/14.3.0 (x86_64)

Some googling around pointed me to <http://youku.io/questions/31571/changing-the-useragent-of-nsurlconnection> which shows how to set the user-agent for the NSURLDownload by using a NSMutableURLConnection:

NSMutableURLRequest* downloadRequest = [[[NSMutableURLRequest alloc] initWithURL:url]
                                autorelease];
[downloadRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[downloadRequest setTimeoutInterval:timeout];
[downloadRequest addValue:@"My Custom User Agent/1.0" forHTTPHeaderField:@"User-Agent"];

NSURLDownload* download = [[[NSURLDownload alloc] initWithRequest:downloadRequest delegate:self] autorelease];

When setting the user-agent this way it contains exactly what you set and nothing else. I would like to continue to append the CFNetwork and Darwin version. Any one know how to do that?

Nick

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Setting the NSURLDownload user agent
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
  • Prev by Date: Re: Does anyone know any Web and/or FTP sites with authentication?
  • Next by Date: Questions on when credentials are used in NSURLSessionDownloadTask
  • Previous by thread: Re: Does anyone know any Web and/or FTP sites with authentication?
  • Next by thread: Re: Setting the NSURLDownload user agent
  • Index(es):
    • Date
    • Thread