Request class

Consists of methods to handle HTTP requests.

Syntax

@interface Request : NSOperation <Requesting> <NSCopying> <NSCoding>

Base protocols

Derived classes

Members

All members of Request, including inherited members.

Methods
Method Description
- (void) addBasicAuthenticationHeaderWithUsername: (NSString *) theUsername andPassword: (NSString *) thePassword Constructs a basic authentication header from the user name and password supplied, and adds it to the request headers.
- (void) addRequestHeader: (NSString *) header value: (NSString *) value Adds a custom header to the request object.
- (void) appendPostData: (NSData *) data Adds data to the POST body.
- (void) appendPostDataFromFile: (NSString *) file Adds data to the post body from a file.
- (void) applyAuthorizationHeader Applies authorization header to a request before it is sent, when shouldPresentCredentialsBeforeChallenge is set to YES.
- (void) applyCookieHeader Creates a cookie header from request cookies and the global store.
+ (unsigned long) averageBandwidthUsedPerSecond Returns a rough average (for the last 5 seconds) of how much bandwidth is being used, in bytes.
+ (NSString *) base64forData: (NSData *) theData Base64 encodes the provided NSData*.
- (void) buildPostBody Creates the POST body.
- (void) buildRequestHeaders Populates the request headers dictionary.
- (void) cancelAuthentication Should be called by delegates when they wish to cancel authentication and stop.
+ (void) clearSession  
+ (const NSDataWritingOptions) dataWritingOptions Returns a mask which determines whether the data should be stored in encrypted form.
+ (NSDate *) dateFromRFC1123String: (NSString *) string Returns a date from a string in RFC1123 format.
+ (NSString *) decodeBase64: (NSString *) string_in Decodes a base64 encoded string.
+ (id< CacheDelegate >) defaultCache Returns the default download cache or NIL if none set at class level.
- (void) enableTracing: (BOOL) value_in Switches traceability status.
+ (void) enableXCSRF: (BOOL) enable Enables XSRF support.
- (void) failWithError: (NSError *) theError Called when a request fails, and lets the delegate know via didFailSelector.
+ (NSDictionary *) fileProtectionAttributes Returns an attributes dictionary used for encrypted file storage or NIL if file protection has been explicitly disabled.
+ (NSInteger) getMaxConcurrentHTTPRequestCount Returns the maximum number of request threads that can be executed in parallel.
- (void) handleNetworkEvent: (CFStreamEventType) type Handles network events as they occur.
- (Request *) HEADRequest Creates a HEAD request appropriate for this request with the same headers.
+ (void) hideNetworkActivityIndicator Hides the network activity spinner.
+ (void) incrementBandwidthUsedInLastSecond: (unsigned long) bytes Used internally to record bandwidth use, and by InputStreams when uploading. It's probably best if you don't mess with this.
- (void) incrementDownloadSizeBy: (long long) length Called when we get a content-length header and shouldResetDownloadProgress is set to TRUE.
- (void) incrementUploadSizeBy: (long long) length Called when a request starts and shouldResetUploadProgress is set to TRUE.
- (id) initWithURL: (NSURL *) newURL Initialize the Request object with a HTTP or HTTPS url.
+ (BOOL) isBandwidthThrottled Returns YES is bandwidth throttling is currently in use.
+ (BOOL) isNetworkInUse Indicates whether there are running requests.
+ (BOOL) isNetworkReachableViaWWAN Returns YES when an iPhone OS device is connected via WWAN, false when connected via WIFI or not connected.
- (BOOL) isResponseCompressed Returns TRUE if the response is gzip compressed.
- (BOOL) isTracingEnabled Returns tracing status.
+ (unsigned long) maxBandwidthPerSecond The maximum number of bytes ALL requests can send or receive in a second.
+ (unsigned long) maxUploadReadLength Returns the maximum amount of data we can read as part of the current measurement period, and sleeps this thread if our allowance is used up.
+ (NSString *) mimeTypeForFileAtPath: (NSString *) path  
+ (void) performSelector: (SEL) selector onTarget: (id *) target withObject: (id) object amount: (void *) amount Helper method used for performing invocations on the main thread (used for progress).
- (void) performThrottling Performs bandwidth throttling.
+ (void) removeCredentialsForHost: (NSString *) host port: (int) port protocol: (NSString *) protocol realm: (NSString *) realm Deletes host credentials from the keychain.
+ (void) removeCredentialsForProxy: (NSString *) host port: (int) port realm: (NSString *) realm Deletes proxy credentials from the keychain.
- (void) removeUploadProgressSoFar Called when authorization is required, as we only find out we do not have some permissions when the upload is complete.
+ (id) requestWithURL: (NSURL *) newURL Creates a Request object with the specified HTTP or HTTPS URL.
+ (id) requestWithURL: (NSURL *) newURL usingCache: (id< CacheDelegate >) cache Creates a Request object with the specified HTTP or HTTPS URL and cache.
+ (id) requestWithURL: (NSURL *) newURL usingCache: (id< CacheDelegate >) cache andCachePolicy: (ECachePolicy) policy Creates a Request object with the specified HTTP or HTTPS URL and cache with predefined cache policy.
- (NSData *) responseData Returns the response as NSData, that is automatically uncompressed where appropriate.
- (NSString *) responseString Returns the contents of the result as an NSString.
- (void) retryUsingSuppliedCredentials Unlocks the request thread so it can resume the request.
+ (void) saveCredentials: (NSURLCredential *) credentials forHost: (NSString *) host port: (int) port protocol: (NSString *) protocol realm: (NSString *) realm Saves host credentials to the keychain.
+ (void) saveCredentials: (NSURLCredential *) credentials forProxy: (NSString *) host port: (int) port realm: (NSString *) realm Saves proxy credentials to the keychain.
- (void) saveCredentialsToKeychain: (NSDictionary *) newCredentials Saves credentials for this request to the keychain.
+ (NSURLCredential *) savedCredentialsForHost: (NSString *) host port: (int) port protocol: (NSString *) protocol realm: (NSString *) realm Returns host credentials from the keychain.
+ (NSURLCredential *) savedCredentialsForProxy: (NSString *) host port: (int) port protocol: (NSString *) protocol realm: (NSString *) realm Returns proxy credentials from the keychain.
- (void) sendE2ETraceXML: (NSURL *) toBaseURL Posts the SAP E2E Trace XML to the specified Solution Manager URL.
- (void) setClientCertificateIdentity: (SecIdentityRef) anIdentity Sets the identity reference (X.509 certificate + private key) for this request; used for secure connections.
+ (void) setDefaultCache: (id< CacheDelegate >) cache Configures a default download cache for all requests.
- (void) setEtag: (NSString *) etag withMatchType: (EtagType) matchType Adds an etag header.
+ (void) setMaxBandwidthPerSecond: (unsigned long) bytes Sets the maximum number of bytes ALL requests can send / receive in a second.
+ (void) setMaxConcurrentHTTPRequestCount: (const unsigned char) cnt Sets the maximum number of request threads that can be executed simultaneously.
+ (void) setProtectionEnabled: (BOOL) flag_in Controls whether the download cache should store files using protection.
+ (void) setShouldThrottleBandwidthForWWAN: (BOOL) throttle Requests can automatically turn throttling on and off, as the connection type changes between WWAN and WiFi.
+ (void) setShouldUpdateNetworkActivityIndicator: (BOOL) shouldUpdate Controls whether the request should take over updating the network activity indicator.
+ (NSOperationQueue *) sharedQueue Returns the shared queue.
+ (void) showNetworkActivityIndicator Shows the network activity spinner.
- (void) startAsynchronous Executes the request in the background.
- (void) startSynchronous Executes a request synchronously and returns control, when the request completes or fails.
+ (void) throttleBandwidthForWWANUsingLimit: (unsigned long) limit Turns on throttling automatically when WWAN is connected using a custom limit, and turns it off automatically when it isn't.
- (void) updateDownloadProgress Updates download progress and notifies the queue and/or downloadProgressDelegate of this request.
+ (void) updateProgressIndicator: (id *) indicator withProgress: (unsigned long long) progress ofTotal: (unsigned long long) total Helper method for interacting with progress indicators to abstract the details of different APIs (NSProgressIndicator and UIProgressView).
- (void) updateProgressIndicators Updates the progress delegates.
- (void) updateUploadProgress Updates upload progress and notifies the queue and/or uploadProgressDelegate of this request.

Usage

It is a wrapper around CFNetwork. 
Features:


Synchronous and asynchronous execution.


Continues downloading and uploading when the application is sent to the background (iOS 4.0+ only).


Network Queue for batch http request processing and progress tracking.


Protected download cache; encrypted offline storage of downloaded content (iOS 4.0+ only).


Secure connection (iOS 4.0+ only).


Easy to extend.


Progress tracking.