gpt4 book ai didi

ios - 在不使用框架的情况下在 iOS 中发布 xml?

转载 作者:行者123 更新时间:2023-11-29 00:50:58 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com