我正在用 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/