服务器看不到“token”和“name+_time”的部分内容
我的代码
NSArray *keysParams = [NSArray arrayWithObjects:@"time",nil];
NSArray *valuesParams = [NSArray arrayWithObjects:time, nil];
NSDictionary *dictParams = [NSDictionary dictionaryWithObjects:valuesParams forKeys:keysParams];
NSError *writeError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictParams options:NSJSONWritingPrettyPrinted error:&writeError];
NSData *imageData = UIImageJPEGRepresentation(getImage1, 0.8);
NSString *boundary = @"&&3rewfwefwfewfhufrbewfuweriwefr";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
//this appends the image
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"photo.jpg\"\r\n",fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
//json
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@_time\" \r\n",fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:jsonData];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//token
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"token\" \r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[token dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
请求正文
imagename(file)
/imagename_time/ - part name
{
time:100
}
/token/ - part name
"string"
我在某个地方有一个错误,但我找不到它。我第一次写多部分帖子。谢谢!