简体   繁体   English

URL 请求:如何设置保留标头?

[英]URL request: How to set reserved headers?

I 'm creating URLRequest with "Authorization" header and it works fine with most of app users but recently I faced that some users cannot make the requst.我正在使用“授权”header 创建 URLRequest,它适用于大多数应用程序用户,但最近我面临一些用户无法提出请求。

apple says that "Certain header fields are reserved (see Reserved HTTP Headers). Do not use this property to set such headers."苹果说“某些 header 字段是保留的(请参阅保留的 HTTP 标头)。不要使用此属性来设置此类标头。” and i found that i used some of these headers我发现我使用了其中一些标题

my question is how to set such headers?我的问题是如何设置这样的标题?

Read the docs阅读文档

Reserved HTTP Headers The URL Loading System handles various aspects of the HTTP protocol for you (HTTP 1.1 persistent connections, proxies, authentication, and so on).保留 HTTP 标头 URL 加载系统为您处理 HTTP 协议的各个方面(HTTP 1.1 持续连接、代理、身份验证等)。 As part of this support, the URL Loading System takes responsibility for certain HTTP headers:作为此支持的一部分,URL 加载系统负责某些 HTTP 接头:

Content-Length内容长度

Authorization授权

Connection联系

Host主持人

Proxy-Authenticate代理验证

Proxy-Authorization代理授权

WWW-Authenticate WWW-认证

If you set a value for one of these reserved headers, the system may ignore the value you set, or overwrite it with its own value, or simply not send it.如果您为这些保留标头之一设置值,系统可能会忽略您设置的值,或者用自己的值覆盖它,或者根本不发送它。 Moreover, the exact behavior may change over time.此外,确切的行为可能会随着时间而改变。 To avoid confusing problems like this, do not set these headers directly.为避免此类混淆问题,请勿直接设置这些标头。

This means you shouldn't manually set these headers.这意味着您不应该手动设置这些标题。 If you REALLY have to then that means there is something wrong with YOUR API.如果您真的必须这样做,那就意味着您的 API 有问题。

https://developer.apple.com/documentation/foundation/nsurlrequest#1776617 https://developer.apple.com/documentation/foundation/nsurlrequest#1776617

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM