zoukankan      html  css  js  c++  java
  • ASIHTTPRequest 简单使用

    ASIHTTPResquest 框架功能强大,应用非常多。

    曾经写过ASIHTTPResquest的导入,如今就看一下基本使用

    记一下当中基础的操作;

    1、发送同步请求;

    NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];//构造url字符串
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];//构造请求对象
        [request startSynchronous];//開始同步请求 <span style="font-family: Arial, Helvetica, sans-serif;">startSynchronous 指的是同步</span>
        NSString *response = [request responseString];//获取请求字符串
        NSLog(@"%@",response);

     

    2、发送异步请求

    NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request startAsynchronous];
        [request setDelegate:self];//设置托付
        NSString *response = [request responseString];
        NSLog(@"%@",response);

    异步请求的delegate;

    与同步请求不同异步请求须要拦截HTTP会话事件。并将事件托付给代理来处理。

    托付:ASIHTTPRequestDelegate

    -(void)requestStarted:(ASIHTTPRequest *)request
    {
        //请求開始的时候调用
    }
    -(void)requestFinished:(ASIHTTPRequest *)request
    {
        //请求完毕的时候调用
    }
    -(void) requestFailed:(ASIHTTPRequest *)request
    {
        //请求失败的时候调用
    }
    -(void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders
    {
        //收到HTTP头的时候调用
    }

    还有非常多托付方法能够点进去看一下。

    ASIHTTPResquest还支持 块

    用块就不须要实现托付了。

  • 相关阅读:
    systemctl命令
    linux下常用命令查看端口占用
    【PostgreSQL】存取jsonb
    tomcat内存溢出之PermGen space
    Spring事务传播机制
    java框架篇---spring aop两种配置方式
    Hibernate一对多实例
    Github 的系统内部都在用什么开源软件?
    这是一个关于软件开发的博客。
    JavaScript中数组的集合和映射
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/7280030.html
Copyright © 2011-2022 走看看