0

I am trying to do a task which I am completely not aware of, that is video uploading to server in objective c. I am a beginner and I was using swift, but now my requirement is in objective c.

Here I have to send an asynchronous request using multipart form data to server with three values. here is the data need to send in body:

body->form-data
projectId : String
sessionId : String
file : file

Its getting crashed at this line

" [urlRequest addValue:@"65" forHTTPHeaderField:@"projectId"];"

Can anyone help me to do this.

Thanks in advance.

NSString *str = [NSString stringWithFormat:@"http://abcdefghijkl.mnopqrst.com:8965/upload"];
NSURL *url = [NSURL URLWithString:str];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[urlRequest addValue:@"65" forHTTPHeaderField:@"projectId"];
[urlRequest addValue:@"43" forHTTPHeaderField:@"sessionId"];
[urlRequest addValue:@"" forHTTPHeaderField:@"file"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    if (error) {
        NSLog(@"Error,%@", [error localizedDescription]);
    } else {
        NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]);
    }
}];
Roman Podymov
  • 4,168
  • 4
  • 30
  • 57
mounika
  • 11
  • 3

1 Answers1

1

You should use NSMutableURLRequest

NSMutableURLRequest is a subclass of NSURLRequest that allows you to change the request’s properties.

NSMutableURLRequest *mutableRequest = [request mutableCopy];
[mutableRequest addValue:@"65" forHTTPHeaderField:@"projectId"];
...

request = [mutableRequest copy];
Davydov Denis
  • 346
  • 1
  • 6
  • Thankyou ...crash is cleared but need to use multipart form data and also I should not use any third parties for url request send. – mounika Jul 29 '19 at 11:36