Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read my application’s CFNetwork-level User-Agent?

I want to programmatically retrieve my application’s User-Agent string. (Note: not the UA of a UIWebView in my application; the UA for NSURLConnection-based HTTP requests.)

There’s lots of guides on how to read an application's UIWebView User-Agent, but none on how to get at the <appname>/1.0 CFNetwork/456.23 string that CFNetwork stuffs inside its HTTP requests. There’s API for CFHTTPMessage to copy out all header fields, but I only have an NSURLRequest and an NSURLResponse, and these are unbridged opaque types. Help!

(Some good background reading: Changing the userAgent of NSURLConnection mentions the format that I want to get at. What HTTP User-Agent does my iOS program advertise itself as? does as well.)

like image 940
cbowns Avatar asked Nov 04 '22 01:11

cbowns


1 Answers

Completely twisted: create a local socket on port 80 and make a local request (to yourself), read the HTTP headers.

like image 185
Cody Caughlan Avatar answered Nov 15 '22 07:11

Cody Caughlan