ios - Content-Length 最大允许长度

标签 ios http content-length

我正在用 ObjectiveC 编程。我想所有的 oC 程序员都使用相当标准的代码来发帖:

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];

目前我收到 NSUInteger 不应用作格式参数的警告。 该警告建议进行类型转换(unsigned long)。并将 %d 替换为 %lu。这听起来合乎逻辑。

在 HTTP 定义中,我找不到 Content-Length 实际上有多长。只是相当模糊的八位字节。那是8位吗?我找不到答案!

最佳答案

Content-Length 的最大值没有具体限制。

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13

14.13 Content-Length
Any Content-Length greater than or equal to zero is a valid value.

还有 setValue:forHTTPHeaderField: 的 Apple 文档在 NSMutableURLRequest 类引用状态中

Additionally, if the length of your upload body data can be determined automatically (for example, if you provide the body content with an NSData object), then the value of Content-Length is set for you.

关于ios - Content-Length 最大允许长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822826/

相关文章:

SVN:DAV 请求失败:411 需要内容长度。 http-chunked-requests

ios - 如何以编程方式创建一个 UIView,其中包含一个 'cutoff' UIImageView?

ios - 将类型为 'UITableViewCell' 的值转换为自定义单元格

http - 如何通过 curl 发送 REST XML POST 请求?

ios - ASIHTTPREQUEST 无内容长度响应(大型 PDF 文件)

C套接字编程接收未知长度的数据

ios - 带有 sqlite 的核心数据仅返回 3 行

ios - subview 不滚动,但滚动条快速滚动

perl - 如何使用 Perl 模块 HTTP::Async 处理超时?

http - gradle - 从 url 下载并解压文件