我正在尝试为多部分形式上传的有效负载计算 content-md5 标头:
NSURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"/upload"
parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.png"
mimeType:@"image/png"];
}];
我试图阅读HTTPBodyStream
:
if ([request HTTPBodyStream]) {
NSInteger result;
uint8_t buffer[1024];
while((result = [[request HTTPBodyStream] read:buffer maxLength:1024]) != 0)
{
if(result > 0) {
[data appendString:[NSString stringWithUTF8String:(char *)buffer]];
} else {...}
}
但我最终陷入了无限循环。有没有办法做到这一点?
更新
[[request HTTPBodyStream] streamError]
如果我打破 while 循环 if ,则在循环null
结束时返回,但是流将不完整。while
result < 0