Hi I am using the following code for NSURLConnection
//initialize new mutable data
responseData = [[NSMutableData alloc] init];
//initialize url that is going to be fetched.
NSURL *url = [NSURL URLWithString:URLCALL];
//initialize a request from url
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url standardizedURL]];
//set http method
[request setHTTPMethod:@"POST"];
//initialize a post data
NSString *postData = [[NSString alloc] initWithString:@"action=3&senderCountryCode=91&senderPhoneNo=9573795715& receiverPhoneNo=9336240585&version=1.0"];
//set request content type we MUST set this value.
[request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
//set post data of request
[request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];
//initialize a connection from request
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
//start the connection
[connection start];
Now I have to add a file as multipart type Please help me how can I use this
If you really want to do it manually and with your file in a NSData *data you can do something like this:
But I would rather use API like AFNetworking which let you do file upload in just a few line:
Try this & check: