NSMutableURLRequest 修改标头字段
NSMutableURLRequest 显然改变了标头字段的大小写。
例如,设置:
[request addValue:myValue forHTTPHeaderField:@"FOOBAR"];
会将标题字段更改为“Foobar”。
有人知道解决这个问题的方法吗?我正在使用一项需要传递区分大小写字段的服务。
另外, NSMutableURLRequest 不应该真正为我做出决定。
NSMutableURLRequest apparently changes case on header fields.
For example, setting:
[request addValue:myValue forHTTPHeaderField:@"FOOBAR"];
will change the header field to "Foobar".
Anybody know a way around this? I am working with a service that requires a case sensitive field to be passed.
Also, NSMutableURLRequest shouldn't really be making the decision for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSMutableURLRequest
遵循 HTTP/1.1 的 RFC 2616 规范< /a> 上面写着:或者 文档,其中写道:
因此我们可以得出结论,
NSURLRequest
实际上只是标准化了标头字段的大小写。多么周到啊。 =)看来你运气不好。
编辑:“我正在使用一项需要传递区分大小写字段的服务。”由于 HTTP/1.1 协议将标头字段名称定义为不区分大小写,因此该服务破坏了协议。互联网上已经充满了当公司和服务试图为了自身利益而忽略协议时会发生什么的例子。 (例如:曾经尝试编写一个在 Firefox 和 IE6 中运行的网页吗?)如果可以的话,我会避免使用此服务,或者写信给他们,让他们知道他们在做什么以及为什么这是错误的。
NSMutableURLRequest
follows the RFC 2616 spec for HTTP/1.1 which says:Or the documentation, which says:
So we can conclude that
NSURLRequest
is really just standardizing capitalization of the header fields. How thoughtful of it. =)Looks like you're out of luck.
Edit: "I am working with a service that requires a case sensitive field to be passed." Since the HTTP/1.1 protocol defines header field names to be case insensitive, this service is breaking the protocol. The internet is already full of examples on what happens when companies and services try to ignore the protocol for their own benefit. (Ex: ever tried to write a webpage that works in Firefox and IE6?) I'd avoid using this service if you could, or write to them and let them know what they're doing and why it's wrong.