0

我对多部分消息的标题格式有疑问。如何为一个部件创建一个具有多个值的标题。

我想要的是 :

--0xKhTmLbOuNdArY-28217FDC-8163-459B-AB09-3DE87210721D
OBR_SORT_IDX:1
OBR_ENUM:1
Content-Disposition: form-data; name="IMAGE"; filename="image1_0.png"
Content-Type: image/png

<theBinData>

我有的:

--0xKhTmLbOuNdArY-28217FDC-8163-459B-AB09-3DE87210721D
Content-Disposition: form-data; name="OBR_ENUM"

1
--0xKhTmLbOuNdArY-28217FDC-8163-459B-AB09-3DE87210721D
Content-Disposition: form-data; name="OBR_SORT_IDX"

1
--0xKhTmLbOuNdArY-28217FDC-8163-459B-AB09-3DE87210721D
Content-Disposition: form-data; name="IMAGE"; filename="image1_0.png"
Content-Type: image/png

<theBinData>

我用于测试的代码:

UIImage *img1 = [UIImage imageNamed:@"alu_texture.png"];
UIImage *img2 = [UIImage imageNamed:@"alu_texture.png"];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strUrl]];
[request setPostBodyFilePath:thePath];
request.shouldStreamPostDataFromDisk = YES;

[request setPostFormat:ASIMultipartFormDataPostFormat];
[request setRequestMethod:@"POST"];

NSString *imgName = [NSString stringWithFormat:@"image%d_%d.png", 1, 0];
NSData *data = [NSData dataWithData: UIImagePNGRepresentation(img1)];
[request addPostValue:@"1" forKey:@"OBR_ENUM"];
[request addPostValue:@"0" forKey:@"OBR_SORT_IDX"];
[request addData:data withFileName:imgName andContentType:@"image/png" forKey:@"IMAGE"];

imgName = [NSString stringWithFormat:@"image%d_%d.png", 1, 1];
data = [NSData dataWithData: UIImagePNGRepresentation(img2)];
[request addPostValue:@"1" forKey:@"OBR_ENUM"];
[request addPostValue:@"1" forKey:@"OBR_SORT_IDX"];
[request addData:data withFileName:imgName andContentType:@"image/png" forKey:@"IMAGE"];

[request setDelegate:self];
[request startAsynchronous]
4

1 回答 1

0

所以我编辑- (void)buildMultipartFormDataPostBodyASIFormDataRequest. 我为多部分标题添加了带有字典的新数组。

buildMultipartFormDataPostBodyfor 循环中的代码for fileData

NSDictionary *d = [self headerMultyPartData][i];
NSArray *keys = d.allKeys;
for(NSString *key in keys)
    [self appendPostString:[NSString stringWithFormat:@"%@: %@\r\n", key, [d valueForKey:key]]];
于 2013-04-24T09:52:17.920 回答