内容长度最大允许长度 [英] Content-Length maximum allowed length

查看:258
本文介绍了内容长度最大允许长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm programming in ObjectiveC. I guess that all oC programmers are using the rather standard code for posting:

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用作格式参数. 警告提示类型转换(无符号长).并且还将%d替换为%lu.这听起来合乎逻辑.

Currently I'm getting warning that NSUInteger should not be used as format argument. The warning suggest a type cast (unsigned long). And also replacing %d with %lu. That sounds logical.

在HTTP定义中,我无法找到Content-Length实际可能要持续多长时间.只是模糊的八位位组.那是8位吗?我找不到答案!

In the HTTP definition, I can not find how long the Content-Length may actually be. Just the rather vague Octet. Is that 8 bits? I can not find the answer!

推荐答案

Content-Length的最大值没有特别限制.

There is no specific limit on the maximum value for the 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.

NSMutableURLRequest类参考状态中的setValue:forHTTPHeaderField:的Apple文档也是如此

Also the Apple documentation for setValue:forHTTPHeaderField: in the NSMutableURLRequest class reference states

此外,如果可以确定您的上载正文数据的长度 自动(例如,如果您为正文内容提供了 NSData对象),然后为您设置Content-Length的值.

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.

这篇关于内容长度最大允许长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆