NSMutableURLRequest and “request body stream exhausted” error

﹥>﹥吖頭↗ 提交于 2019-12-01 07:47:57
alex-i

From the looks of it, it seems that you're not setting @"Content-Length" in the header.

The way I do it is like this:

NSUInteger fileSize = [[[[NSFileManager defaultManager] attributesOfItemAtPath:_dataStreamLocation error:nil] objectForKey:NSFileSize] unsignedIntegerValue];
[request setValue:[NSString stringWithFormat:@"%u", fileSize] forHTTPHeaderField:@"Content-Length"];

Either way, I was doing batch uploading and occasionally got the body stream exhaustion error. From what I could tell, the issue was that I only had few free space on the device, and the temporary files would get deleted automatically before some uploads being finished (when receiving the error I tested to check if the file was still there, and it wasn't).

I was encountering this same problem, what fixed it for me was retaining the stream then releasing it at the end of the asynchronous HTTP transaction. Doesn't seem like this should be necessary, however it got me around the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!