#pragma mark-This is a private method, try not to use the property directly in the method, because generally the property is associated with the interface, we can use the attribute #pragma the Mark Post login method by the way of the parameter-(void) Loginwithpostwithname: (NSString *) userName pwd: (NSString *) pwd{//1 determine address nsurl nsstring *urlstring = [NSString StringW ithformat:@ "www.baidu.com"]; Nsurl *url = [Nsurl urlwithstring:urlstring]; 2 Build Request Nsmutableurlrequest (post requires this) nsmutableurlrequest *request = [Nsmutableurlrequest Requestwithurl:url]; Network access timeout time [request settimeoutinterval:2.0f]; 1) The Post request method, the network request is the Get method by default, so if we use the POST request, we must declare the request way. [Request sethttpmethod:@ "POST"]; 2) The data body of the POST request, the data body in the POST request, if there is Chinese, do not need to convert. Because the Atausingencoding method has already implemented transcoding. NSString *bodystr = [NSString stringwithformat:@ "username=%@&password=%@", username, pwd]; Convert nstring to NSData nsdata *body = [Bodystr datausingencoding:nsutf8stringencoding]; NSLog (@ "Body data%@", body); [Request Sethttpbody:body]; 3 Establish and start the connection nsrulconnection//nsurlconnection *conn = [nsurlconnection connectionwithrequest:request delegate:self];//[Conn start]; Start the connection, which is where the network request has occurred. This is an asynchronous connection request, and when the request is sent out, it is referred to the agent for processing. 3 No proxy synchronization request, nsurlresponse *response = nil; Nserror *error = nil; The second, three parameters are pointers to the pointer, all to use the accessor, this method is a synchronous method. The synchronization operation is not completed and the following code will not execute. NSData *data = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; Subsequent processing of the data that is accessed synchronously if (data = nil) {//accepts data, indicates work nsstring *str = [[NSString alloc]initwithdata:data Encoding:ns Utf8stringencoding]; NSLog (@ "%@", str); }else if (data = = Nil && Error! = nil)//does not receive data, but error is nil. Indicates that an empty data is accepted. {NSLog (@ "accept null data"); }else{NSLog (@ "%@", error.localizeddescription); Request error. }////server notification ready, ready for transit data//Self.serverdata = [Nsmutabledata data];}