我使用 AFNetworking 进行网络操作
那么向https://api.box.com/2.0/files/content发送请求的正确方法是什么?现在我收到 HTTP//1.1 500 Internal Server Error
代码
NSMutableData *body = [NSMutableData data];
NSString *boundaryString = [NSString stringWithFormat:@"rn-------------------------%.0frn", [[NSDate date] timeIntervalSince1970]];
NSData *boundary = [boundaryString dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:kBoxNetFileUploadURLFormat];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[BoxNet attachAuthHeaderForRequest:request];
[request addValue:[BoxNet SHA1:content] forHTTPHeaderField:@"Content-MD5"];
[request addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=\"%@\"", boundaryString] forHTTPHeaderField:@"Content-Type"];
[body appendData:boundary];
[body appendData:[@"Content-Disposition: form-data; name=\folder_id\"" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[folderID dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:boundary];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"%@\"; name=\"filename\"", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:content];
[body appendData:boundary];
[request setHTTPBody:body];
[request setValue:[NSString stringWithFormat:@"%d", body.length] forHTTPHeaderField:@"Content-Length"];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
completion(JSON, nil);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *err, id JSON) {
completion(JSON, err);
}];
[operation start];