我有一个项目,我从中检索用户的数据并保存在本地xml文件中。我在模拟器上做了这一切。现在我想在iPhone设备上部署。但问题是如何使用Web服务从iphone向服务器发送文件(XML)?
答案 0 :(得分:1)
您可以通过HTTP发布它:
NSString * xmlString = @"<test><message length="5">Hello</message></test>";
NSURL * serviceUrl = [NSURL URLWithString:@"http://my.company.com/myservice"];
NSMutableURLRequest * serviceRequest = [NSMutableURLRequest requestWithURL:serviceUrl];
[serviceRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[serviceRequest setHTTPMethod:@"POST"];
[serviceRequest setHTTPBody:[xmlString dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse * serviceResponse;
NSError * serviceError;
serviceResponse = [NSURLConnection sendSynchronousRequest:serviceRequest returningResponse:&serviceResponse error:&serviceError];
取自here