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];
  • 相关阅读:
    Mysql的select加锁分析
    浅析Kubernetes的工作原理
    HTTP/2部署使用
    Amazon新一代云端关系数据库Aurora
    为什么 kubernetes 天然适合微服务
    深入解读Service Mesh背后的技术细节
    微服务的接入层设计与动静资源隔离
    Prim算法和Kruskal算法介绍
    DAG及拓扑排序
    BFS和DFS
  • 原文地址:https://www.cnblogs.com/xcy617/p/2862713.html
Copyright © 2011-2022 走看看