How to make HTTP Post request with JSON body in Swift像这样没有使用这样的框架我需要 xml 发布任何人都可以帮助我......
最佳答案
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];
使用上面的代码实现你想要的
关于ios - 在不使用框架的情况下在 iOS 中发布 xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38148545/