• 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: stringWithContentsOfURL bug? (gzip issue)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringWithContentsOfURL bug? (gzip issue)


  • Subject: Re: stringWithContentsOfURL bug? (gzip issue)
  • From: Peter Maurer <email@hidden>
  • Date: Fri, 7 Jan 2005 17:24:07 +0100

I have some data on a webserver in MySQL databases, so I wrote a PHP script that loads the relevant data, and creates a long string that formats the data in good old plist format. Then I print this out.

I try to access the string using the stringWithContentsOfURL: method (which I have used in quite some projects already, so I already know this should work). When my string is short, maybe 5 lines when displayed in Safari, the string gets loaded fine.
Like this:
<dict><key>Category</key><array><dict><key>category_id</ key><string>1</string><key>category_name</key><string>Finder</ string></dict><dict><key>category_id</key><string>2</ string><key>category_name</key><string>Mail</string></ dict><dict><key>category_id</key><string>3</ string><key>category_name</key><string>Safari</string></dict></ array></dict>


But when I add a longer string, suddenly I get garbled data...

I've had similar problems, and they did indeed turn out to be caused by the gzip issue Frederick has outlined. As far as I remember, this is a known bug: The -stringWithContentsOfURL: method tells the server "Sure, send me gzipped data, if you want to. I can handle it.", but then fails to unzip them.


One way to circumvent this issue is to use the following methods I have written for one of my projects:

//----------------------

-(NSData*)dataFromNSURLConnectionWithURL: (NSURL*)theURL
{
if( theURL )
{
NSMutableURLRequest * theURLRequest;
if( theURLRequest = [NSMutableURLRequest requestWithURL: theURL] )
{
[theURLRequest setCachePolicy: NSURLRequestReloadIgnoringCacheData];
[theURLRequest setTimeoutInterval: 5.0];
return [NSURLConnection sendSynchronousRequest: theURLRequest returningResponse: nil error: nil];
}
}
return nil;
}


-(NSDictionary*)dictionaryFromNSURLConnectionWithURL: (NSURL*)theURL
{
NSData * theData;
if( theData = [self dataFromNSURLConnectionWithURL: theURL] )
{
return [(NSDictionary*)CFPropertyListCreateFromXMLData(kCFAllocatorDefault, (CFDataRef)theData, kCFPropertyListImmutable, NULL) autorelease];
}
return nil;
}


//----------------------

Cheers,

Peter.

_______________________________________________
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: stringWithContentsOfURL bug? (gzip issue)
      • From: Frederick Cheung <email@hidden>
References: 
 >stringWithContentsOfURL bug? (From: Benjámin Salánki <email@hidden>)

  • Prev by Date: Re: [Newbie] How to make application reappear after a close?
  • Next by Date: Re: [Newbie] How to make application reappear after a close?
  • Previous by thread: Re: stringWithContentsOfURL bug?
  • Next by thread: Re: stringWithContentsOfURL bug? (gzip issue)
  • Index(es):
    • Date
    • Thread