Re: Loading contents of URL in a string
Re: Loading contents of URL in a string
- Subject: Re: Loading contents of URL in a string
- From: John Stiles <email@hidden>
- Date: Wed, 07 Dec 2005 22:18:31 -0800
The data is probably gzip-compressed.
I don't remember the solution off the top of my head, but it's come up
on the list before. Most people agree that NSString isn't as helpful as
it could be here :) The Safari NSURLxxx classes might give better results.
Tito Ciuro wrote:
Hello,
I'm trying to load the contents of a web page into an NSString for
further processing. I've tried several things, which sort of work, but
not entirely. I've tried something like this:
NSString *string = @"http://...";
NSURL *url = [NSURL URLWithString:string];
NSData *data = [url resourceDataUsingCache:NO];
NSString *urlContents = [[[NSString alloc]initWithData:data
encoding:NSASCIIStringEncoding]autorelease];
NSString *otherURLContents = [NSString stringWithContentsOfURL:url];
If I use something like "http://www.apple.com", no problem: both
urlContents and otherURLContents show the HTML source. However, if I
specify something like "http://wwwa.accuweather.com/index-
forecast.asp?partner=accuweather&myadc=0&zipcode=94025&u=1", the
contents show up in this form:
\u008b\u00a1\u0080`$\u00d8\u0090@\u00ec\u00c1\u0088\u00cd\u00e6\u0092
\u00eciG#)\u00ab*\u0081\u00caeVe]f@\u00cc\u00ed\u009d\u00bc\u00f7
\u00de{\u00ef\u00bd\u00f7\u00de{\u00ef\u00bd\u00f7\u00ba;
\u009dN'\u00f7\u00df\u00ff?\fdl\u00f6\u00ceJ\u00da\u00c9\u009e!\u0080 \u00aa\u00c8?~|?"\u00ff\u00efez\u0099\u00d7MQ-?\u00fbhw\u00bc
\u00f3\u00d1\u00efq\u00f4'\u008f\u00d7\u00a7_\u009e\u00bc\u00f9}^
\u009e\u00a6\u00f3
...
...
...
Why is that? If I display the page using Safari, its source can be
easily seen... what am I missing?
Thanks,
-- Tito _______________________________________________
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