NSURLRequest HTTPBody在服务器端被截断

时间:2016-05-23 16:34:59

标签: ios node.js http tcp nsurlrequest

通过互联网发送NSData。发送的数据长度为 8278 字节。但收到的数据仅为 8029 字节。你知道为什么数据被服务器截断了吗?是数据大小的HTTP / TCP限制吗?或者是node.js限制?

let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
let path = (documentsPath.stringByAppendingPathComponent("Assets") as NSString).stringByAppendingPathComponent("\(upsert.recordName).\(field2.key)")

let url: NSURL = NSURL(string: "xxx")!
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.setValue("image/jpg", forHTTPHeaderField: "content-type")
request.setValue("\(upsert.recordName).\(field.key)", forHTTPHeaderField: "filename")
request.HTTPBody = NSData(contentsOfFile: path)

NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()).dataTaskWithRequest(request, completionHandler: {data, urlResponse, error in }).resume()

1 个答案:

答案 0 :(得分:0)

删除

request.setValue("image/jpg", forHTTPHeaderField: "content-type")

行将阻止减少和转换内容。