• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSURLConnection and 404s
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >RE: NSURLConnection and 404s (From: Rudi Sherry <email@hidden>)

  • Prev by Date: [Moderator] Re: Cocoa-Java and the Future
  • Next by Date: Re: [ANN] Cocoa Style for ObjC: 1 and 2
  • Previous by thread: RE: NSURLConnection and 404s
  • Next by thread: Cocoa-Java and the Future
  • Index(es):
    • Date
    • Thread