• 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: Loading contents of URL in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading contents of URL in a string


  • Subject: Re: Loading contents of URL in a string
  • From: Casey Fleser <email@hidden>
  • Date: Thu, 8 Dec 2005 02:07:16 -0600

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
  • Follow-Ups:
    • Re: Loading contents of URL in a string
      • From: Tito Ciuro <email@hidden>
    • Re: Loading contents of URL in a string
      • From: Frederick Cheung <email@hidden>
References: 
 >Loading contents of URL in a string (From: Tito Ciuro <email@hidden>)

  • Prev by Date: Re: Loading contents of URL in a string
  • Next by Date: NSObject Foundation tool memory issue?
  • Previous by thread: Re: Loading contents of URL in a string
  • Next by thread: Re: Loading contents of URL in a string
  • Index(es):
    • Date
    • Thread