Re: NSURLConnection and 404s
Re: NSURLConnection and 404s
- Subject: Re: NSURLConnection and 404s
- From: John Stiles <email@hidden>
- Date: Tue, 26 Oct 2004 16:35:33 -0700
That's exactly what I needed. Thanks!
On Oct 26, 2004, at 4:18 PM, Rudi Sherry wrote:
In didReceiveResponse: you should be able to get the status from the
NSURLResponse; it is likely actually an NSURLHTTPRespone, and there
is a
method in there to get the status (use respondsToSelector:):
if (response respondsToSelector:@selector(statusCode)]
{
int statusCode = [ response statusCode ];
if (statusCode == 404)
{
}
}
-----Original Message-----
From: cocoa-dev-bounces+rsherry=email@hidden
[mailto:cocoa-dev-bounces+rsherry=email@hidden] On Behalf
Of
John Stiles
Sent: Tuesday, October 26, 2004 3:36 PM
To: Cocoa Posting
Subject: NSURLConnection and 404s
I'm connecting to a web server with NSURLConnection and downloading
data.
It works great; however, I would like to detect 404s ("File Not Found")
or other anomalous conditions.
Right now, as far as I can see, a 404 and successful download are
impossible to differentiate in my code. They both call the following
things in my delegate:
- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response
OK, I got a response. The NSURLResponse doesn't give me any useful
data and so far everything seems hunky-dory.
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData
*)data
OK, here's some data. Unfortunately, without a lot of hacks, my code
can't tell the difference between data that reads "404 - File not
found!" and regular data. Many web servers also serve up something
fancy, like a picture or even a redirect to a different page, when a
404 error is encountered.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
OK, we're done. Nothing returned any errors.
Amidst these calls I don't see any place to hook in and grab the HTTP
status value, or in fact any of the HTTP response headers.
What am I missing? Certainly there must be someplace that exposes the
HTTP status code to the outside world.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden