문제

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.)

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top