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

前端 未结 3 1701
离开以前
离开以前 2020-12-15 14:00

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.

3条回答
  •  囚心锁ツ
    2020-12-15 14:43

    You can HTTP POST it:

    NSString * xmlString = @"Hello";
    
    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,

提交回复
热议问题