NSURL problems
-
Has anyone successfully used NSURL and NSData to fetch from the web? I'm
trying the following:
NSData *stuff;
NSURL *url;
url = [[NSURL alloc] initWithString: @"http://www.yahoo.com/"];
stuff = [[NSData alloc] initWithContentsOfURL: url];
It always seems to be able to parse the url in the NSURL initialization but
the data init hangs for a long time and then times out. What's the trick
here?
If I'm behind a firewall (this fails in either case) do I need to do
anything else special?
Thanks,
Matt -
On vendredi, octobre 12, 2001, at 10:19 , Matt Brandt wrote:> Has anyone successfully used NSURL and NSData to fetch from the web? I'm
> trying the following:
>
> NSData *stuff;
> NSURL *url;
>
> url = [[NSURL alloc] initWithString: @"http://www.yahoo.com/"];
> stuff = [[NSData alloc] initWithContentsOfURL: url];
>
> It always seems to be able to parse the url in the NSURL initialization
> but
> the data init hangs for a long time and then times out. What's the trick
> here?
>
> If I'm behind a firewall (this fails in either case) do I need to do
> anything else special?
>
As far as I know, the initWithContentsOfURL methods don't support proxy
authentication... do you have to enter a password in your browser to
browse the web ? I have no idea about regular firewall support but there
might be the same problem. It works flawlessly here without a
proxy/firewall. Have you tried with [[NSString alloc]
initWithContentsOfURL:] ? Does it work?
Wilfried de Denterghem -
I'm pretty sure that NSData doesn't work together wiith NSURL that
way if it's not a file URL. However, if you check out NSURL and/or
NSURLHandle, you can get what you want more easily. Plus, you have
the ability to to background loads, too.
Try
stuff = [url resourceDataUsingCache:YES];
and see if that gets you anywhere -- if that doesn't work, it may
be a firewall issue.
Dan
On Friday, October 12, 2001, at 01:19 PM, Matt Brandt wrote:> Has anyone successfully used NSURL and NSData to fetch from the
> web? I'm
> trying the following:
>
> NSData *stuff;
> NSURL *url;
>
> url = [[NSURL alloc] initWithString: @"http://www.yahoo.com/"];
> stuff = [[NSData alloc] initWithContentsOfURL: url];
>
> It always seems to be able to parse the url in the NSURL
> initialization but
> the data init hangs for a long time and then times out. What's the
> trick
> here?
>
> If I'm behind a firewall (this fails in either case) do I need to do
> anything else special?
>
> Thanks,
>
> Matt
>
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
>
--
Dan Wood
<dwood...>
http://www.karelia.com/
http://www.bikealameda.org/
Mac OS X Developer: Online Resume: http://www.karelia.com/resume.html -
On Friday, October 12, 2001, at 04:19 PM, Matt Brandt wrote:> Has anyone successfully used NSURL and NSData to fetch from the web? I'm
> trying the following:
>
> NSData *stuff;
> NSURL *url;
>
> url = [[NSURL alloc] initWithString: @"http://www.yahoo.com/"];
> stuff = [[NSData alloc] initWithContentsOfURL: url];
>
> It always seems to be able to parse the url in the NSURL initialization
> but
> the data init hangs for a long time and then times out. What's the trick
> here?
>
I think this may be due to the fact that many of the 'URL'
initializers only work with file:// urls.
try getting the NSData back from the NSURL method
url = [[NSURL alloc] initWithString: @"http://www.yahoo.com/"]; stuff=[url
resourceDataUsingCache:NO]; -
Le samedi 13 octobre 2001, Ã 07:46 , <macosx-dev-request...> a
écrit :> Subject: NSURL problems
> Date: Fri, 12 Oct 2001 15:19:31 -0500
>
> Has anyone successfully used NSURL and NSData to fetch from the web? I'm
> trying the following:
>
> NSData *stuff;
> NSURL *url;
>
> url = [[NSURL alloc] initWithString: @"http://www.yahoo.com/"];
> stuff = [[NSData alloc] initWithContentsOfURL: url];
>
> It always seems to be able to parse the url in the NSURL initialization
> but
> the data init hangs for a long time and then times out. What's the trick
> here?
>
> If I'm behind a firewall (this fails in either case) do I need to do
> anything else special?
>
> Thanks,
>
Hi,
You can try this :
NSString *url;
NSString *htmlContent;
scriptResult = [NSString stringWithContentsOfURL:[NSURL
URLWithString:@"http://www.yahoo.fr"]];
It works for me, but the problem I currently have, is that when you are
using a proxy server the connection failed after a timeout (for several
proxies).
I don't know if it's a 10.0.X bug, are you testing your code on 10.1 ?
I cant' get an answer for this problem I have (and maybe you have too).
The only way I see is to use libcurl (unix library available at
http://curl.haxx.se/).
You can also use CURLHandle (Cocoa object using libcurl at
http://curl.haxx.se/libcurl/cocoa/).
Thierry -
So now, thanks to several suggestions, I've tried the following:
data = [url resourceDataUsingCache:YES/NO];
string = [NSString stringWithContentsOfURL: url];
and they both time out. I'm behind a firewall today but this gets the same
result when accessing internal sites as well as external. Our proxy server
doesn't need any authentication from where I'm running but I'm wondering if
these methods pick up on the proxy server at all. I can't find any methods
to explicitly point to the proxy server, do they get it from network prefs
automagically?
Matt


