how send file (txt/XML) from iphone to server(web or email)

老子叫甜甜 提交于 2019-12-18 02:57:36

问题


Hi I want to send text or XML from iphone to another desktop machine. Is there any way so that I can use Email to send file as attachment or can send it by HTTP POST method.

Please help me.


回答1:


You can HTTP POST it:

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.

Hope this helps,




回答2:


Have a look at NSMutableURLRequest if you want to send an HTTP post request with a payload.

Other than that, you can use the url scheme mailto: to send text to the Mail application and send it manually from there.

Your best bet is to look into the NSMutableURLRequest class though.




回答3:


http://developer.apple.com/iphone/library/samplecode/MailComposer/

I found it :)



来源:https://stackoverflow.com/questions/1130969/how-send-file-txt-xml-from-iphone-to-serverweb-or-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!