Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone

Overview

ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier. It is written in Objective-C and works in both Mac OS X and iPhone applications.

It is suitable performing basic HTTP requests and interacting with REST-based services (GET / POST / PUT / DELETE). The included ASIFormDataRequest subclass makes it easy to submit POST data and files using multipart/form-data.

It provides:

  • A straightforward interface for submitting data to and fetching data from webservers
  • Download data to memory or directly to a file on disk
  • Submit files on local drives as part of POST data, compatible with the HTML file input mechanism
  • Stream request bodies directly from disk to the server, to conserve memory
  • Resume for partial downloads
  • Easy access to request and response HTTP headers
  • Progress delegates (NSProgressIndicators and UIProgressViews) to show information about download AND upload progress
  • Auto-magic management of upload and download progress indicators for operation queues
  • Basic, Digest + NTLM authentication support, credentials are automatically re-used for the duration of a session, and can be stored for later in the Keychain.
  • Cookie support
  • [NEW] Requests can continue to run when your app moves to the background (iOS 4+)
  • GZIP support for response data AND request bodies
  • The included ASIDownloadCache class lets requests transparently cache responses, and allow requests for cached data to succeed even when there is no network available
  • [NEW] ASIWebPageRequest – download complete webpages, including external resources like images and stylesheets. Pages of any size can be indefinitely cached, and displayed in a UIWebview / WebView even when you have no network connection.
  • Easy to use support for Amazon S3 – no need to fiddle around signing requests yourself!
  • Full support for Rackspace Cloud Files
  • [NEW] Client certificates support
  • Supports manual and auto-detected proxies, authenticating proxies, and PAC file auto-configuration. The built-in login dialog lets your iPhone application work transparently with authenticating proxies without any additional effort.
  • Bandwidth throttling support
  • Support for persistent connections
  • Supports synchronous & asynchronous requests
  • Get notifications about changes in your request state via delegation or [NEW] blocks (Mac OS X 10.6, iOS 4 and above)
  • Comes with a broad range of unit tests

ASIHTTPRequest is compatible with Mac OS 10.5 or later, and iOS 3.0 or later.

Documentation is available here.

Comments
  • No Progress for ASIS3Request's queued in ASINetworkQueue

    No Progress for ASIS3Request's queued in ASINetworkQueue

    I've setup multiple ASIS3Request's and added them to a ASINetworkQueue. The S3 Requests have a download and temporary download path, resume download is allowed.

    I've setup a UIProgressView as downloadProgressDelegate for the queue.

    However it seems that the progress is not updated. I've debugged the methods:

    • (void)incrementDownloadSizeBy:(unsigned long long)bytes and
    • (void)incrementDownloadProgressBy:(unsigned long long)bytes in the ASINetworkQueue class and both times the "bytes" value passed to these methods is 0.

    Any ideas how to solve this?

    opened by leviathan 11
  • CRASH *** -[ASIHTTPRequest performThrottling]: message sent to deallocated instance 0x9aca00

    CRASH *** -[ASIHTTPRequest performThrottling]: message sent to deallocated instance 0x9aca00

    *** -[ASIHTTPRequest performThrottling]: message sent to deallocated instance 0x9aca00

    see screenshot http://skitch.com/steipetee/d9cax/system

    i'm using v1.8/latest 2ff7b0cded41f97c5076

    just used ASIHTTPRequest (with blocks), did nothing special...

    opened by steipete 10
  • Can ASINetworkQueue get a NSDictionary

    Can ASINetworkQueue get a NSDictionary "userInfo" ?

    In order to distinguish between multiple queues it would be great if ASINetworkQueue gets a "userInfo" NSDictionary.

    I've already added it to this gist source here: http://gist.github.com/215015

    opened by leviathan 8
  • CDN Managment URL key

    CDN Managment URL key

    I was having trouble making ASICloudFilesCDNRequests, kept getting a generic "Unable to start HTTP connection" error.

    I was able to track down the bug to the following section of code in ASICloudFilesRequest.m:

    68  if (![request error]) {
    69  NSDictionary *responseHeaders = [request responseHeaders];
    70  authToken = [responseHeaders objectForKey:@"X-Auth-Token"];
    71  storageURL = [responseHeaders objectForKey:@"X-Storage-Url"];
    72  cdnManagementURL = [responseHeaders objectForKey:@"X-Cdn-Management-Url"];
    73  }
    

    Obtaining cdnManagementURL using the key "X-Cdn-Management-Url" returned (null) and was causing other problems later on down the line. Turns out the correct key uses a capitalized "CDN" like so:

    "X-CDN-Management-Url"

    API Reference: http://docs.rackspace.com/files/api/v1/cf-devguide/content/Authentication-d1e639.html#d6e265

    opened by chrisozenne 7
  • Why is the default timeout 10 seconds?

    Why is the default timeout 10 seconds?

    Hi, Ben, great framework, thanks a lot.

    I have a quick question, why is the default timeout only 10 seconds? The default for NSURLRequest is 60? I seem to get quite a few timeout errors when testing on an iPhone, is there any problem with just setting the default to 60?

    Thanks, Dan

    opened by danthorpe 7
  • Crash when blocks are deallocated and have strong references to views

    Crash when blocks are deallocated and have strong references to views

    I'm having crashes when blocks retain elements and are released in own threads.

    bool _WebTryThreadLock(bool), 0x7d7c3e0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now... (EXC_BAD_ACCESS)

    http://skitch.com/steipetee/d9xwx/system

    opened by steipete 7
  • memory leaks with garbage collection

    memory leaks with garbage collection

    If I run 'build and analyze' on a garbage-collection-enabled project using ASIHTTPRequest, I get 10 warnings with the message "Potential leak (when using garbage collection) of an object..." (in ASIFormDataRequest.m and ASIHTTPRequest.m). Could you look into this? (It seems it's mostly related to objects allocated using CoreFoundation functions and deallocated using autorelease.)

    opened by mackuba 7
  • readStream null on occasion

    readStream null on occasion

    I don't have really good reproduce instructions for you on this one because it is so rare but it does happen. I use a standard NSOperationQueue to push all ASIHTTPRequests into and I push a lot of requests through it limited to 4 simulataneously.

    Around line 717 of ASIHTTPRequest.m there are (rare) occasions when the readStream is NULL and the following line crashes the app:

    [self setTotalBytesSent:[[(NSNumber *)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue]];

    opened by prime31 7
  • strange handling of session

    strange handling of session

    Hi,

    I have a big problem. When i start my app, I do two requests. One is for login, so i send my username and password. My server responds fine (im logged in). And the second one is loading some data. The two requests are started at the same time. The problem is probably the response time. it seems like when the 'load data' request starts first and ends secondso it's like:

    1. start 'load data'
    2. start 'login'
    3. finish 'login' - (it says im logged in successfully)
    4. finish 'load data'

    it seems like my app thinks i'm logged in, but i'm not. when i try to make a request and the server responds with $_SESSION['login'], it's empty ... when i don't make the 'load data' request, everything is okay ... when i do it after the 'login' request ends, it's okay, too. so it seems to be a problem only when i start the requests at the same time ....

    I encountered the problem when my app was buggy. I started it up, and sometimes it worked, and sometimes not. I started to log the responses and saw that it somehow depends on the order of the requestsDidFinish for those two requests.

    I can say it's 100% not bug on my server-side script as i'm using it also on other platforms this way, and don't have such problems.

    Thanks for your response... and hope you solve it soon :)

    opened by kukosk 6
  • The ability to set a global user agent

    The ability to set a global user agent

    The need to set a global user agent for an application can come up, and when there are multiple ASIHTTPRequests it gets cumbersome to have to manually set the User-Agent for each request:

    [request addRequestHeader:@"User-Agent" value:[NSString stringWithFormat:@"CE API v%@", kCEAPIVersion]];
    

    In the commit you'll see its now possible to set a global User-Agent which can still be overwritten on a per request basis. If this was merged, you'll be able to do the following instead:

    [ASIHTTPRequest setUserAgent:[NSString stringWithFormat:@"CE API v%@", kCEAPIVersion]];
    
    opened by dewski 6
  • Feature Request: Block Based API

    Feature Request: Block Based API

    We should introduce a newer, block based API for the finish/fail actions. I'd love to use that instead of those didFinishSelectors. (Works on OS3 too with PLBlocks)

    opened by steipete 6
  • [ASIHTTPRequest destroyReadStream] + 3908 error

    [ASIHTTPRequest destroyReadStream] + 3908 error

    Anyone has a fix for iOS16?

    Crashed: Thread 0 libsystem_platform.dylib 0x608c _os_unfair_lock_recursive_abort + 36 1 libsystem_platform.dylib 0x898 _os_unfair_lock_lock_slow + 280 2 CoreFoundation 0xd10c0 CFSocketInvalidate + 132 3 CFNetwork 0x167498 _CFNetworkErrorGetLocalizedDescription + 308716 4 CoreFoundation 0x16c70 CFArrayApplyFunction + 72 5 CFNetwork 0x145014 _CFNetworkErrorGetLocalizedDescription + 168296 6 CoreFoundation 0x7ea10 _CFRelease + 316 7 CoreFoundation 0xd13f8 CFSocketInvalidate + 956 8 CFNetwork 0x151aec _CFNetworkErrorGetLocalizedDescription + 220224 9 CoreFoundation 0x435dc _CFStreamClose + 108 10 CFNetwork 0x140984 _CFNetworkErrorGetLocalizedDescription + 150232 11 CFNetwork 0x106a5c _CFURLConnectionCopyTimingData + 8728 12 CFNetwork 0x124e3c _CFNetworkErrorGetLocalizedDescription + 36752 13 CFNetwork 0x12686c _CFNetworkErrorGetLocalizedDescription + 43456 14 CFNetwork 0x12ee1c _CFNetworkErrorGetLocalizedDescription + 77680 15 CoreFoundation 0x435dc _CFStreamClose + 108 16 CFNetwork 0x142470 _CFNetworkErrorGetLocalizedDescription + 157124 17 CoreFoundation 0x435dc _CFStreamClose + 108 18 App 0x1e3d64 -[ASIHTTPRequest destroyReadStream] + 3908 (ASIHTTPRequest.m:3908) 19 App 0x1df578 -[ASIHTTPRequest failWithError:] + 2301 (ASIHTTPRequest.m:2301) 20 App 0x1dd7cc -[ASIHTTPRequest checkRequestStatus] + 1738 (ASIHTTPRequest.m:1738) 21 App 0x1dd25c -[ASIHTTPRequest updateStatus:] + 1661 (ASIHTTPRequest.m:1661) 22 Foundation 0x835f8 __NSFireTimer + 96 23 CoreFoundation 0xce35c CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 32 24 CoreFoundation 0x8a9d8 __CFRunLoopDoTimer + 940 25 CoreFoundation 0x2e598 __CFRunLoopDoTimers + 288 26 CoreFoundation 0x7bfcc __CFRunLoopRun + 1896 27 CoreFoundation 0x80ed4 CFRunLoopRunSpecific + 612 28 App 0x1e7bf4 +[ASIHTTPRequest runRequests] + 5010 (ASIHTTPRequest.m:5010) 29 Foundation 0x5b808 NSThread__start + 716 30 libsystem_pthread.dylib 0x16cc _pthread_start + 148 31 libsystem_pthread.dylib 0xba4 thread_start + 8

    opened by mobipos 0
  • Does the project support the IPV6-only network?

    Does the project support the IPV6-only network?

    I have a project to use it as Network connection, but currently the app update is rejected by Apple because the IPV6-only reason, could you please help me to confirm that the ASIHTTPRequest can work correctly in IPV6-only network?

    opened by KimXiao 0
A frida tool that capture GET/POST HTTP requests of iOS Swift library 'Alamofire' and disable SSL Pinning.

FridaHookSwiftAlamofire A frida tool that capture GET/POST HTTP requests of iOS Swift library 'Alamofire' and disable SSL Pinning. 中文文档及过程 Features Ca

neilwu 69 Dec 16, 2022
Menet is a TCP network middleware that can be dynamically modified through HTTP requests.

Menet Menet is a TCP network middleware that can be dynamically modified through HTTP requests. This is an experimental project, do NOT use it in prod

Nik 2 May 19, 2022
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support

Networking was born out of the necessity of having a simple networking library that doesn't have crazy programming abstractions or uses the latest rea

Nes 1.3k Dec 17, 2022
Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Igor 2 Sep 16, 2022
a NSURLCache subclass for handling all web requests that use NSURLRequest

EVURLCache What is this? This is a NSURLCache subclass for handeling all web requests that use NSURLRequest. (This includes UIWebView) The EVURLCache

Edwin Vermeer 296 Dec 18, 2022
Http - Demo for Http Layer

http Example To run the example project, clone the repo, and run pod install fro

null 0 Jan 24, 2022
Http Request wrapper written in Swift

Net Net is a HttpRequest wrapper written in Swift Features GET, POST, PUT, DELETE method Powerful request params: nested params, number, string, dic,

Le Van Nghia 304 Jun 29, 2022
🌸 Powerful Codable API requests builder and manager for iOS.

This lib is about network requests with blackjack, roulette and craps! Using it you will be able to convert your massive API layer code into an awesom

CodyFire 251 Jan 8, 2023
Synchronous requests for AFNetworking 1.x, 2.x, and 3.x

AFNetworking-Synchronous A minimal category which extends AFNetworking to support synchronous requests. Usage 3.x pod 'AFNetworking', '~> 3.0' pod

Paul Melnikow 160 Dec 7, 2022
QwikHttp is a robust, yet lightweight and simple to use HTTP networking library for iOS, tvOS and watchOS

QwikHttp is a robust, yet lightweight and simple to use HTTP networking library. It allows you to customize every aspect of your http requests within a single line of code, using a Builder style syntax to keep your code super clean.

Logan Sease 2 Mar 20, 2022
Request adapter for URL requests from "MovieLister" demo app (Swift for Good book, a chapter by Ben Scheirman)

RequestAdapter Request adapter for URL requests from "MovieLister" demo app (Swift for Good book, a chapter by Ben Scheirman) The code is taken from:

Mihaela Mihaljevic Jakic 0 Nov 22, 2021
Approov Integration Examples 0 Jan 26, 2022
CoreNetwork module with the basic functionality of requests to the network

CoreNetwork module with the basic functionality of requests to the network

Moscow Metro 4 Apr 27, 2022
VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps.

Simple, Fast and Easy. Introduction VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps. How

Victor Freitas 4 Aug 22, 2022
Deal with query items, HTTP headers, request body and more in an easy, declarative way

Reusable system for complex URL requests with Swift. Deal with query items, HTTP headers, request body and more in an easy, declarative way. Check out our engineering blog to learn more!

Parable Health 19 Sep 5, 2022
This package is meant to make http request of an easy way inspiren in the architecture of Moya package

NetworkAgent This package is meant to make http request of an easy way inspiren in the architecture of Moya package. This package is 100% free of depe

Angel Rada 19 Sep 8, 2022
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

Ronan Rodrigo Nunes 89 Dec 26, 2022
A custom wrapper over AFNetworking library that we use inside RC extensively

AFNetworkingHelper A very simple wrapper over the most amazing networking library for objective C, AFNetworking. We extensively use it inside RC and i

Betacraft 16 Aug 3, 2021
Swift/Obj-C HTTP framework with a focus on REST and JSON

Now Archived and Forked PMHTTP will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork of PHMT

Postmates Inc. 509 Sep 4, 2022