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];
  • 相关阅读:
    jQuery -JQ方法大全
    Javascript模块化编程:模块的写法
    angular 路由的简单使用
    jQuery Validate验证框架
    网站出现403 Forbidden错误的原因和解决办法
    js下拉刷新
    bootstrap栅格系统的属性及使用
    AJAX 跨域请求
    用js实现分页效果
    用一个例子读懂 RequireJS
  • 原文地址:https://www.cnblogs.com/xcy617/p/2862713.html
Copyright © 2011-2022 走看看