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: Tito Ciuro <email@hidden>
- Date: Thu, 8 Dec 2005 14:16:14 -0500
Hi Casey,
Nope... still doesn't work. Puzzling...
Thanks for the help :-)
-- Tito
On 08/12/2005, at 3:07, Casey Fleser wrote:
Not sure why that method doesn't work, but give this a try:
NSString *string = @"http://wwwa.accuweather.com/index-forecast.asp?
partner=accuweather&myadc=0&zipcode=94025&u=1";
NSURL *url = [NSURL URLWithString:string];
NSURLResponse *response;
NSData *data;
NSError *error;
data = [NSURLConnection sendSynchronousRequest: [NSURLRequest
requestWithURL: url] returningResponse: &response error: &error];
On Dec 7, 2005, at 11:32 PM, 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\u00ed\u00bd`I\u0096%&/m\u00ca{J\u00f5J\u00d7\u00e0t
\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,
_______________________________________________
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