• 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 404
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection and 404


  • Subject: Re: NSURLConnection and 404
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sun, 09 Jun 2013 17:57:47 +0700

On 9 Jun 2013, at 16:54, Jean-Daniel Dupas <email@hidden> wrote:

>
> Le 9 juin 2013 à 11:35, Gerriet M. Denkmann <email@hidden> a écrit :
>
>> This works fine, but blocks my for 1 sec on a good day - who know how long if the net is slow:
>>
>> url = something/which/might/exist/or/not.gif
>> data = [ NSData dataWithContentsOfURL: url options: mask error: &outError ];
>>
>> So I am trying to use NSURLConnection instead. Also works fine.
>>
>> Only: if my url does not exist, then the old method returned data = nil. Very good.
>>
>> Using  NSURLConnection I always get some answer - either image data or a lengthy string like:
>>
>> HTML 4.0 Transitional//EN">
>> <html>
>> 	<head>
>> 		<title>Error 404 - Page not found</title>
>> 	</head>
>> 	<body bgcolor="#000000">
>> [...]
>>
>>
>> Is there a way to get just the status (in this case 404) without parsing the data?
>> I looked at the NSURLConnection delegate methods, but did not find anything which looked appropriate.
>>
>> Gerriet.
>
> The NSConnectionDelegate protocol has a method that pass you the response:
>
> - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
>
> You can test if the response is of type NSHTTPURLResponse (which should always be the case when you send an HTTP request), and then use the -[NSHTTPURLResponse statusCode] method to get the status.

Excellent! This is exactly what I was looking for.

Thank you very much! Merci beaucoup!


Kind regards,

Gerriet.




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >NSURLConnection and 404 (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: NSURLConnection and 404 (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Re: NSURLConnection and 404
  • Next by Date: Re: NSPopUpButtonCell - How To Get The Changed Value
  • Previous by thread: Re: NSURLConnection and 404
  • Next by thread: Re: NSURLConnection and 404
  • Index(es):
    • Date
    • Thread