2009-07-15 10 views

risposta

0

Dai un'occhiata a NSMutableURLRequest se vuoi inviare una richiesta di post HTTP con un carico utile.

Oltre a questo, è possibile utilizzare lo schema url mailto: per inviare del testo all'applicazione Mail e inviarlo manualmente da lì.

La soluzione migliore è comunque esaminare la classe NSMutableURLRequest.

9

È possibile 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]; 

è anche possibile impostare altri Header HTTP come Content-Length allo stesso modo.

Spero che questo aiuti,

+0

sendSynchronousRequest: returningResponse: errore: restituisce un oggetto NSData e non il NSURLResponse hai usato. –

+0

Grazie, è bello ... grazie mille – sinh99

Problemi correlati