iOS Development ASIHTTPRequest Class Library

Source: Internet
Author: User

ASIHTTPRequest is an open source project directly on Cfnetwork that provides a more convenient and powerful package for HTTP network transmissions than the official. Its features are as follows:
1, the downloaded data is saved directly to the memory or file system
2, provide API for direct commit (HTTP POST) file
3, can directly access and modify HTTP request and response header
4, easy to get upload and download progress information
5, asynchronous request and queue, automatic management of upload and download queue management machine
6. Support for authentication and authorization
7,cookie
8, request-and-response gzip
9, Proxy request

1. To add asihttprequest related files to the Xcode project, the required file list is as follows: ASIHTTPRequestConfig.h ASIHTTPRequestDelegate.h ASIProgressDelegate.h as ICacheDelegate.h ASIHTTPRequest.h asihttprequest.m ASIDataCompressor.h asidatacompressor.m asidatadecompressor. H asidatadecompressor.m ASIFormDataRequest.h ASIInputStream.h asiinputstream.m asiformdatarequest.m asinetwo RkQueue.h asinetworkqueue.m ASIDownloadCache.h asidownloadcache.m ASIAuthenticationDialog.h Asiauthenticationdi ALOG.M Reachability.h (under the external/reachability directory of the source code) REACHABILITY.M (in the source code external/reachability directory)
2, add Class library Cfnetwork.framework systemconfiguration.framework, mobilecoreservices.framework, libz.1.2.5.dylib these class libraries
3, Import header file #import "ASIHTTPRequest.h"

Create a synchronization request
Nsurl *url = [Nsurl urlwithstring:@ "http://allseeing-i.com"]; ASIHTTPRequest *request = [ASIHTTPRequest Requestwithurl:url]; [Request startsynchronous]; Nserror *error = [Request Error];if (!error) {nsstring *response = [request responsestring]; In general, asynchronous requests should be used instead of synchronous requests when the main thread In the ASIHTTPRequest synchronization request, the application's interface is locked and no action can be made until the request is complete. Create an asynchronous request Nsurl *url = [Nsurl urlwithstring:@ "http://allseeing-i.com"]; ASIHTTPRequest *request = [ASIHTTPRequest Requestwithurl:url]; [Request Setdelegate:self]; [Request startasynchronous]; -(void) requestfinished: (ASIHTTPRequest *) request{//Use this method when reading the returned content as text nsstring *responsestring = [request responsestring];//This method nsdata *responsedata = [request ResponseData] When reading the returned content in binary form; -(void) requestfailed: (ASIHTTPRequest *) request{nserror *error = [request ERROR];}

If the program launches arc, you need to set the file-fno-objc-arc

ARC is a new feature of iOS 5, called arc (Automatic Reference counting). Simply put, it is the code that automatically joins the Retain/release, and the code that originally needed to manually add a reference count to handle memory management can be automatically completed by the compiler. This mechanism is started in IOS 5/mac OS X 10.7 and can be used with Xcode4.2. The simple understanding of arc is that by specifying the syntax, the compiler (LLVM 3.0) automatically generates the reference count of the instance when the code is compiled to manage part of the code. At one point, arc is not a GC, it is just a static analyzer tool of code.

Then in Xcode often need to import some foreign code files, if the imported files using the arc mechanism and your current project does not use arc, then Xcode will give a warning, or error. How do we deal with these problems:

To see if arc is on,the "objective-c Automatic Reference Counting" option is yes, which means open.

Click the project navigation file--Select Targets--> Select Build Phases--Expand compile Sources

This time, we see the name of the second column:Compiler Flags

Double-click the file you want to use for arc, and enter -fobjc-arc,

Now this file can be compiled using the ARC mechanism at compile time.

As above, if you want to use the ARC mechanism code without the arc mechanism, you only need to enter -fno-objc-arc

iOS Development ASIHTTPRequest class library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.