zoukankan      html  css  js  c++  java
  • 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");
        }
    }
  • 相关阅读:
    ODAC配置
    mysql 创建索引和删除索引
    Linux下安装多个tomcat
    CentOS7/6 关闭防火墙
    从navicat中导入sql文件过大:Got a packet bigger than 'max_allowed_packet' bytes
    手动添加jar包到本地仓库
    mysql权限
    Linux常用命令
    centos 6.5安装VMware tools
    MySql 查询数据库中所有表名以及对比分布式库中字段和表的不同
  • 原文地址:https://www.cnblogs.com/bing-ge/p/4615954.html
Copyright © 2011-2022 走看看