zoukankan      html  css  js  c++  java
  • 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];
  • 相关阅读:
    Spring中@Autowired注解、@Resource注解的区别 (zz)
    ECLIPSE使用HG插件去上载 GOOGLE.CODE下的代码
    jrebel
    myeclipse 上安装 Maven3
    web项目目录结构
    笔记 利用python进行数据分析
    算法浅入浅出之Textrank
    算法浅入浅出之TF-IDF
    python库之jieba小试牛刀 3
    python库之jieba小试牛刀 2
  • 原文地址:https://www.cnblogs.com/xcy617/p/2862713.html
Copyright © 2011-2022 走看看