1NSString * URLString =@"www.baidu.com";2Nsurl * URL =[Nsurl urlwithstring:[urlstring stringbyaddingpercentescapesusinge ncoding:nsutf8stringencoding]; 4NSString * poststring =@"theregioncode= Hunan";5NSData * PostData = [poststring datausingencoding:nsutf8stringencoding];//Convert request parameter string to NSData type 7Nsmutableurlrequest * Request =[[Nsmutableurlrequest alloc]init];8[Request Sethttpmethod:@"Post"];//Specify the request method9[Request Seturl:url];//set the requested addressTen[Request Sethttpbody:postdata];//set parameters for the request One ANsurlresponse *response; -Nserror *error; -NSData * Backdata = [nsurlconnection sendsynchronousrequest:request returningres ponse:&response error:&ERROR]; - if(Error) { -NSLog (@"Error:%@", [Error localizeddescription]); -}Else{ +NSLog (@"Response:%@", response); -NSLog (@"backdata:%@", [[NSString alloc]initwithdata:backdata Encoding:nsutf 8StringEncoding]); +}
Post mode when the parameters are placed inside the httpbody, and the need to transcode the string into a response to the NSData type, in the interface document is generally indicated in the Transcoding method, the need to transcode in the specified way, here the UTF8, there are gb2312. After the request has been built, use nsurlconnection as the Get method for requesting data.
HTTP request on iOS: Post method