[英]how send file (txt/XML) from iphone to server(web or email)
Hi I want to send text or XML from iphone to another desktop machine. 嗨,我想从iphone发送文本或XML到另一台桌面计算机。 Is there any way so that I can use Email to send file as attachment or can send it by HTTP POST method. 有什么方法可以使用Email将文件作为附件发送,或者可以通过HTTP POST方法发送它。
Please help me. 请帮我。
You can HTTP POST it: 你可以HTTP POST它:
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];
You can also set other HTTP Header such as content-length the same way. 您也可以以相同的方式设置其他HTTP标头,例如内容长度。
Hope this helps, 希望这可以帮助,
Have a look at NSMutableURLRequest if you want to send an HTTP post request with a payload. 如果要发送带有效负载的HTTP post请求,请查看NSMutableURLRequest。
Other than that, you can use the url scheme mailto: to send text to the Mail application and send it manually from there. 除此之外,您可以使用url方案mailto:将文本发送到Mail应用程序并从那里手动发送。
Your best bet is to look into the NSMutableURLRequest class though. 最好的办法是查看NSMutableURLRequest类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.