Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > stringWithContentsOfURL: bug... Rickster maybe ? ;)

stringWithContentsOfURL: bug... Rickster maybe ? ;)
Thread Tools
altimac
Forum Regular
Join Date: May 2001
Location: France
Status: Offline
Reply With Quote
Dec 11, 2003, 05:55 PM
 
hi everybody !

i've encoutered a strange bug with method stringWithContentsOfURL: from class NSString.

i pass it a completly valid URL, but it returns garbage string instead of a valid html page content...

the url is this one :
http://ypng.infospace.com/home/yello...otopia&qc=&qs=

as you can see it perfectly works in Safari

Now a short piece of Code :

NSURL *requestURL = [NSURL URLWithString:@"http://ypng.infospace.com/home/yellow-pages/redir.htm?top=internal&fromform=qsearch&wqhqn=&qhq n=Geotopia&qc=&qs="];

if(requestURL) {
NSString* returnedHTML = [NSString stringWithContentsOfURL:requestURL];

NSLog(@"look at this strange string: %@",returnedHTML);
[returnedHTML writeToFile:@"/path/to/a/garbage/html/file.html" atomically:YES];
}
else {
NSLog(@"the URL is not RFC compliant...");
}

now just look at the content of file.html...

can anybody explain me why it is only garbage ?
first i thought it was an encoding problem, so i tried using NSData then change the encoding etc... but no way to make this works !

Can it be a problem with basic browser/Server communication (i know VERY little about http protocol...) : i mean, that maybe the http server wants to dialog with the "client" part of the NSStringWithContentsOfURL because it needs some informations (?), but what's behind this method does not manage this type of communication ? (i remember GET etc...)


please, can i have an explanation on this, and better, a solution !!! :-D

thanks !
CarraFix, the traffic shaper for OS X !

Enjoy The [CFx] Community !
http://www.carrafix.com
     
Uncle Skeleton
Addicted to MacNN
Join Date: Nov 2002
Location: Rockville, MD
Status: Offline
Reply With Quote
Dec 11, 2003, 06:37 PM
 
having not tried your example, might it be compressed? I've seen websites send their pages as .gz, and the browser decompresses (or sometimes not) transparently. I've used CURLHandle to get these pages for my app instead of [NSString stringWithContentsOfURL]
     
altimac  (op)
Forum Regular
Join Date: May 2001
Location: France
Status: Offline
Reply With Quote
Dec 12, 2003, 04:15 AM
 
no i don't think so, but i'll try CURLHandle
thanks

any other idea ?
CarraFix, the traffic shaper for OS X !

Enjoy The [CFx] Community !
http://www.carrafix.com
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:54 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,