• ASIHttpRequest框架使用说明-----post请求 以及监听网络


    1.导入头文件  
    #import " ASIFormDataRequest.h"
     
    2.创建一个 ASIFormDataRequest 对象
    ASIFormDataRequest *formRequest = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:UrlStr]];
     
    3.设置代理
    formRequest.delegate = self;
     
    4.设置请求体  下面相当于 q=武侠
    [formRequest addPostValue:@"武侠" forKey:@"q"];
     
    5.发送请求
    [formRequest startAsynchronous];
     
    6.实现代理方法
    1)遵守协议 ASIHTTPRequestDelegate
    2)实现协议方法 
    - (void)requestFinished:(ASIHTTPRequest *)request    请求完成的时候调用
    request.responseString  取字符串
    request.responseData   取data数据
     
     
    - (void)requestFailed:(ASIHTTPRequest *)request  请求出错时调用
    与get请求的区别就是  
    1.包含头文件不同
    2.创建的request对象不同
    3.要设置请求体
     
    监听网络
    1. //监听网络状态的变化
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onNetWorkChanged:) name:kReachabilityChangedNotification object:nil];
        Reachability *reach = [Reachability reachabilityWithHostName:@"www.baidu.com"];
        [reach startNotifier];//开始检测网络状态
    2.
    - (void)onNetWorkChanged:(NSNotification *)notification
    {
        Reachability *oneReach = [notification object];
        if (oneReach.isReachable) {
            NSLog(@"network can reach");
        }else {
            NSLog(@"network canot reach");
        }
    }
  • 相关阅读:
    Directory文档目录操作
    文件序列化和反序列化
    COOKIE
    转载深入ASP.NET MVC之二:路由模块如何工作
    Running 32Bit RDP on 64 Bit Windows OS
    MS CRM Isv Web.config设置
    QualifyLead PlugIn(转)
    MS CRM帮助访问不正确,
    (转)CrmTrace encountered an error. Additional Info:Error in GetFileName MS CRM
    MS CRM 2011储存电子邮件凭证
  • 原文地址:https://www.cnblogs.com/bing-ge/p/4615954.html
Copyright © 2020-2023  润新知