0

How to make HTTP Post request with JSON body in Swift like in this there are not using frameworks like this i need xml posting can any one help me...

Community
  • 1
  • 1

1 Answers1

1
 NSError *error;

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
NSURL *url = [NSURL URLWithString:@"Your SERVER"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
NSString *xmlString = @"<?xml version=\"1.0\"?>\n<yourdata></yourdata>";
[request setHTTPBody:[xmlString dataUsingEncoding:NSUTF8StringEncoding]];


NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

// handel response & error
}];

[postDataTask resume];     

Use the above code to achieve what you want

vishnuvarthan
  • 492
  • 1
  • 6
  • 23