ios - NSData/setHTTPBody 的最大参数大小?

标签 ios iis-7 http-post nsdata maxrequestlength

我的 iPad 应用程序将文件列表作为字符串参数 fileList 发送到如下 Web 方法:

NSString *post = [NSString stringWithFormat:@"sessionID=%@&fileList=%@&dateTime=%@&userID=%@", sessionID, fileList, timeOpened, userID];    
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *comparisonURLString = SERVER_COMPARE_URL_STRING;
NSURL *comparisonURL = [NSURL URLWithString:comparisonURLString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:comparisonURL];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

[request setHTTPMethod:@"POST"];
[request addValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

当文件列表超过一定大小时,它似乎会被截断。我在 the apple documentation 中找不到有关最大尺寸的任何信息。另外,无论如何,后续参数似乎都可以正常接收,但在我将其视为问题的可能根源之前,我想知道是否有人知道是否存在这样的限制?

服务器正在运行 IIS7,并且 webConfig maxRequestLength 设置为 1048576。

-编辑-

问题根源:

我创建了一个 webmethod,它只接受整个 POST 作为参数,并删除与号 (&) 之后的所有内容,所以我认为这可能是问题所在,而不是参数大小。

最佳答案

认为问题可能是缺少 Content-Type HTTP 请求 header 字段:

[request setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

还使用 UTF-8 对有效负载进行编码:

NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

关于ios - NSData/setHTTPBody 的最大参数大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133189/

相关文章:

iphone - UIBarButtonItem外观iOS5字体

ios - Objective C - 在 View Controller 的 UIView 子类上设置标签属性

ios - 为 CocoaPods 的 pod 设置部署目标

iis-7 - 如何使用 appcmd 在远程服务器上创建网站?

iphone - 从 iphone 中的 sqlite 和 table View 中删除数据

http - 如何引导 IE9 允许来自 Gmail 的链接端点使用 HTTP 重定向到 PDF?

c# - 如何在 ASP.NET 缓存应用程序中超过 IIS7 的 60% 内存限制

node.js - Node js request.post 回调未触发

javascript - 向 Office 加载项发送请求

javascript - Angular 2 http post null Web Api Core