ios中http的两种请求方法:get与post

   get主要负责查询,安全性低,操作方便;

   post安全性高,操作如下:

 NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];  
    //设置提交目的url  
    [request setURL:[NSURL URLWithString:kUserLoginCheckUrl]];  
    //设置提交方式为 POST  
    [request setHTTPMethod:@"POST"];  
    //设置http-header:Content-Type  
    //这里设置为 application/x-www-form-urlencoded ,如果设置为其它的,比如text/html;charset=utf-8,或者 text/html 等,都会出错。不知道什么原因。  
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];  
    //设置http-header:Content-Length  
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];  
    //设置需要post提交的内容  
    [request setHTTPBody:postData];  
      
    //定义  
    NSHTTPURLResponse* urlResponse = nil;  
    NSError *error = [[NSError alloc] init];  
    //同步提交:POST提交并等待返回值(同步),返回值是NSData类型。  
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; 
这个基本就是完整的请求过程
 NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
原文地址:https://www.cnblogs.com/xcy617/p/2862713.html