Class CPURLConnection

CPObject
    extended byCPURLConnection

@implementation CPURLConnection : CPObject

An interface to downloading content at a specified URL. Using one of the class methods, you can obtain the data.


Method Summary
+(CPURLConnection)connectionWithRequest:(CPURLRequest)aRequest delegate:(id)aDelegate
          Creates a url connection with a delegate to monitor the request progress.
+(CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:(CPURLResponse)aURLResponse error:(CPError)anError
          Sends a request for the data from a URL.
+(void)setClassDelegate:(id)delegate
-(id)initWithRequest:(CPURLRequest)aRequest delegate:(id)aDelegate
-(id)initWithRequest:(CPURLRequest)aRequest delegate:(id)aDelegate startImmediately:(BOOL)shouldStartImmediately
          Default class initializer.
-(void)cancel
          Cancels the current request.
-(id)delegate
          return the delegate.
-(void)start
          Start the connection.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass

Delegate Method Summary
-(void)connection:(CPURLConnection)connection didFailWithError:(id)error
          Called when the connection encounters an error.
-(void)connection:(CPURLConnection)connection didReceiveResponse:(CPHTTPURLResponse)response
          Called when the connection receives a response.
-(void)connection:(CPURLConnection)connection didReceiveData:(CPString)data
          Called when the connection has received data.
-(void)connectionDidFinishLoading:(CPURLConnection)connection
          Called when the URL has finished loading.
-(void)connectionDidReceiveAuthenticationChallenge:(id)connection
          This class delegate method allows you to set global behavior for when authentication challenges (401 status codes) are returned.


Method Detail

connectionWithRequest

+(CPURLConnection)connectionWithRequest:(CPURLRequest)aRequest delegate:(id)aDelegate
Creates a url connection with a delegate to monitor the request progress.
Parameters:
aRequest - contains the URL to obtain data from
aDelegate - will be sent messages related to the request progress
Returns:
a connection that can be started to initiate the request

sendSynchronousRequest

+(CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:(CPURLResponse)aURLResponse error:(CPError)anError
Sends a request for the data from a URL. This is the easiest way to obtain data from a URL.
Parameters:
aRequest - contains the URL to request the data from
aURLResponse - not used
anError - not used
Returns:
the data at the URL or nil if there was an error

setClassDelegate

+(void)setClassDelegate:(id)delegate
Parameters:
delegate

initWithRequest

-(id)initWithRequest:(CPURLRequest)aRequest delegate:(id)aDelegate
Parameters:
aRequest
aDelegate

initWithRequest

-(id)initWithRequest:(CPURLRequest)aRequest delegate:(id)aDelegate startImmediately:(BOOL)shouldStartImmediately
Default class initializer. Use one of the class methods instead.
Parameters:
aRequest - contains the URL to contact
aDelegate - will receive progress messages
shouldStartImmediately - whether the start method should be called from here
Returns:
the initialized url connection

cancel

-(void)cancel
Cancels the current request.

delegate

-(id)delegate
return the delegate

start

-(void)start
Start the connection. Not needed if you used the class method +connectionWithRequest:delegate:

Delegate Method Detail

connection

-(void)connection:(CPURLConnection)connection didFailWithError:(id)error
Called when the connection encounters an error.
Parameters:
connection - the connection that had an error
error - the error, which is either a javascript DOMException or an http status code (javascript number/CPNumber)

connection

-(void)connection:(CPURLConnection)connection didReceiveResponse:(CPHTTPURLResponse)response
Called when the connection receives a response.
Parameters:
connection - the connection that received a response
response - the received response

connection

-(void)connection:(CPURLConnection)connection didReceiveData:(CPString)data
Called when the connection has received data.
Parameters:
connection - the connection that received data
data - the received data

connectionDidFinishLoading

-(void)connectionDidFinishLoading:(CPURLConnection)connection
Called when the URL has finished loading.
Parameters:
connection - the connection that finished loading Class Delegate Method:

connectionDidReceiveAuthenticationChallenge

-(void)connectionDidReceiveAuthenticationChallenge:(id)connection
This class delegate method allows you to set global behavior for when authentication challenges (401 status codes) are returned.
The recommended way to handle this method is to store a reference to the connection, and then use whatever method you have to authenticate yourself. Once you've authenticated yourself, you should cancel and then start the connection:
[connection cancel];
[connection start];
Parameters:
connection - the connection that received the authentication challenge.

Created on Sat Sep 13 14:15:43 PDT 2008