zoukankan      html  css  js  c++  java
  • ASIHttpRequest网络请求第三方类库使用方法详解

    一. 第一步首先你要从网络上下载ASIHttpRequestlib, 下载以后解压,增加到你的工程里面,

    这个时间检查工程内部是否已经导入成功,文件结构如下:

    ASIHTTPRequestConfig.h
    ASIHTTPRequestDelegate.h
    ASIProgressDelegate.h
    ASICacheDelegate.h
    ASIHTTPRequest.h
    ASIHTTPRequest.m
    ASIDataCompressor.h
    ASIDataCompressor.m
    ASIDataDecompressor.h
    ASIDataDecompressor.m
    ASIFormDataRequest.h
    ASIInputStream.h
    ASIInputStream.m
    ASIFormDataRequest.m
    ASINetworkQueue.h
    ASINetworkQueue.m
    ASIDownloadCache.h
    ASIDownloadCache.m
    ASIAuthenticationDialog.h
    ASIAuthenticationDialog.m
    Reachability.h (在源码的 External/Reachability 目录下)
    Reachability.m (在源码的 External/Reachability 目录下)

     二.  导入相应的类库,(这里不说怎么导入了就)CFNetwork.framework,SystemConfiguration.framework, MobileCoreServices.framework,CoreGraphics.framework和libz.1.2.3.dylib

    三.  在使用之前

    在使用ASIHTTPRequest之前,请确认已经正确安装,然后在需要应用它的代码文件头部,加入:

    #import “ASIHTTPRequest.h”

    这样就可以在代码中使用ASIHTTPRequest相关的类。

    四.  普通的get请求。

    NSURL *url = [NSURL URLWithString:@"http://rss.sina.com.cn/news/marquee/ddt.xml"];

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

    [request startSynchronous];

    NSError *error = [request error];

    NSString *response = [request responseString];

    五 . 参数请求


    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:@"Ben" forKey:@"first_name"];
    [request setPostValue:@"Copsey" forKey:@"last_name"];
    [request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];
    [request addData:imageData withFileName:@"george.jpg" andContentType:@"image/jpeg"forKey:@"photos"];

    这是两种基本的asi请求的方式,startSynchronous    startAynchronous,同步与异步,只是是否会开启子线程之说

  • 相关阅读:
    struts2标签解释
    通过注册表修改XP默认登陆用户
    6类常见开机故障
    摩尔定律
    小红伞扫描病毒类型
    newInstance()方法和new关键字
    常见恶意软件种类及说明
    jquery1.9 中这些方法已经被删除(live、die、sub........)
    (转)Ubuntu下JDK7安装全过程并调试第一个带包的java程序
    js取消气泡事件、阻止浏览器的默认行为
  • 原文地址:https://www.cnblogs.com/ccguo/p/3355477.html
Copyright © 2011-2022 走看看