#define XLBoundary @"XL"
#define XLLine @"\r\n"
#define XLEncode(string) [string dataUsingEncoding:NSUTF8StringEncoding]
NSURL *serverURL = [NSURL URLWithString:@""];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverURL];
request.HTTPMethod = @"POST";
NSMutableData *body = [NSMutableData data];
NSDictionary *params = @{@"":@""};
[body appendData:XLEncode(@"--")];
[body appendData:XLEncode(XLBoundary)];
[body appendData:XLEncode(XLLine)];
NSURL *urlPath = [[NSBundle mainBundle] URLForResource:@"" withExtension:@""];
NSURLRequest *requestPath = [NSURLRequest requestWithURL:urlPath];
NSURLResponse *response = nil;
[NSURLConnection sendSynchronousRequest:requestPath returningResponse:&response error:nil];
NSString *mimeType = response.MIMEType;
NSString *type = [NSString stringWithFormat:@"Content-Type:%@", mimeType];
[body appendData:XLEncode(type)];
[body appendData:XLEncode(XLLine)];
NSData *fileData = [NSData dataWithContentsOfURL:urlPath];
[body appendData:XLEncode(XLLine)];
[body appendData:fileData];
[body appendData:XLEncode(XLLine)];
NSString *fileName = @"";
NSString *disposition = [NSString stringWithFormat:@"Content-Disposition:form-data; name=\"file\"; filename\"%@\"", fileName];
[body appendData:XLEncode(disposition)];
[body appendData:XLEncode(XLLine)];
[params enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
[body appendData:XLEncode(@"--")];
[body appendData:XLEncode(XLBoundary)];
[body appendData:XLEncode(XLLine)];
NSString *disposition = [NSString stringWithFormat:@"Content-Disposition:form-data; name=\"%@\"", key];
[body appendData:XLEncode(disposition)];
[body appendData:XLEncode(XLLine)];
[body appendData:XLEncode(XLLine)];
[body appendData:XLEncode([obj description])];
[body appendData:XLEncode(XLLine)];
}];
[body appendData:XLEncode(@"--")];
[body appendData:XLEncode(XLBoundary)];
[body appendData:XLEncode(@"--")];
[body appendData:XLEncode(XLLine)];
request.HTTPBody = body;
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", XLBoundary];
[request setValue:contentType forHTTPHeaderField:@"Content-type"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
}];