http://lizhuang.iteye.com/blog/1833297
1. Preparation Stage
NSString *urlstring = [NSString stringwithformat:@ "http://jssb.zust.edu.cn/androidLogin.action"];
Nsmutableurlrequest *request = [[[[Nsmutableurlrequest alloc] init] autorelease];
[Request Seturl:[nsurl urlwithstring:urlstring];
[Request sethttpmethod:@ "POST"];
2, set the head
NSString *contenttype = [NSString stringwithformat:@ "Text/xml"];
[Request Addvalue:contenttype Forhttpheaderfield: @ "Content-type"];
3, the data content body settings
Nsmutabledata *postbody = [Nsmutabledata data];
[Postbody appenddata:[[nsstring stringwithformat:@ "id=%@&password=%@&role=%@", @ "admin02", @ "admin02", @ " Dean "] datausingencoding:nsutf8stringencoding];
[Request Sethttpbody:postbody];
When the XML is delivered:
Nsmutabledata *postbody = [Nsmutabledata data];
[Postbody appenddata:[[nsstring stringwithformat:@ "<request action=\" login\ ">"] datausingencoding: Nsutf8stringencoding]];
[Postbody appenddata:[[nsstring stringwithformat:@ "<Body>"] datausingencoding:nsutf8stringencoding];
[Postbody appenddata:[[nsstring stringwithformat:@ "<Username>wangjun</Username>"] datausingencoding: Nsutf8stringencoding]];
[Postbody appenddata:[[nsstring stringwithformat:@ "<Password>password</Password>"] datausingencoding: Nsutf8stringencoding]];
[Postbody appenddata:[[nsstring stringwithformat:@ "<PlatformID>2</PlatformID>"] datausingencoding: Nsutf8stringencoding]];
[Postbody appenddata:[[nsstring stringwithformat:@ "<PlatformVersion>3.1.3</PlatformVersion>"] Datausingencoding:nsutf8stringencoding]];
[Postbody appenddata:[[nsstring stringwithformat:@ "<taskviewername>ip 1.3</taskviewername>"] Datausingencoding:nsutf8stringencoding]];
[Postbody appenddata:[[nsstring stringwithformat:@ "<TaskViewerVersion>3</TaskViewerVersion>"] Datausingencoding:nsutf8stringencoding]];
[Postbody appenddata:[[nsstring stringwithformat:@ "</Body>"] datausingencoding:nsutf8stringencoding];
[Postbody appenddata:[[nsstring stringwithformat:@ "</Request>"] datausingencoding:nsutf8stringencoding];
Post
[Request Sethttpbody:postbody];
4. Request response
nshttpurlresponse* urlresponse = nil;
Nserror *error = [[Nserror alloc] init];
NSData *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&urlresponse Error: &error];
NSString *result = [[NSString alloc] Initwithdata:responsedata encoding:nsutf8stringencoding];
Nsurlrequest Post Mode Request Server sample