NSUrlRequest: where an app can find the default headers for HTTP request?

不羁岁月 提交于 2019-11-29 00:22:25

Your app cannot. It's done all down in CFNetwork - Communicating with HTTP Servers. I believe it just adds missing header values not supplied by NSURLRequest.

The defaults are:

  • USER-AGENT "AppName - Eng/1.0 CFNetwork/485.13.9 Darwin/10.7.0"
  • ACCEPT "*/*"
  • ACCEPT-LANGUAGE "en-us"
  • ACCEPT-ENCODING "gzip, deflate"
  • CONNECTION "keep-alive"

hmm... maybe you might want to try within

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse

method in your custom nsurlconnection class. although the documentation mentions something about redirects, this is certainly worth looking into.

That may be an overkill, but based on Matt Gallagher's blog post I've created even more simpler local HTTP listener and sent a separate [mutableCopy]ed request to it to be able to read and output all HTTP headers that this request has.

Better solution must be to setup a local HTTP request catcher, it must look nicer I think, but for the scope of simple demo just to show all sent/received headers this solution is OK.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!