Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
Hi all,

I need to get data from web service, one of the data is an URL String. For example: www.testing.aspx?username=123&pwd=456. But after I get this URL String data from web service and used in my Iphone Project, in my Iphone Project this URL String become www.testing.aspx?username=123&pwd=456.

So, I used a method called - (NSString *)stringByAddingPercentEscapesUsingEncoding: (NSStringEncoding)enc and using NSUTF8StringEncoding. The resulted URL String is : www.testing.aspx?username=123&2pwd=456. The resulted URL string seems not same as what I get from web service.

Am I doing something wrong?

Anyone have any idea to encode an URL String? Any idea are appreciated.

Thanks a lot. :)
 
Firstly, if you have an percent-escaped URL, you need to use the opposite of what you've tried, which is stringByReplacingPercentEscapesUsingEncoding:.

But this isn't a percent-escaped URL. The percent-escaped version of & is not & but %26.

What is &? It's the HTML/XML decimal numeric character reference for &. More commonly the named character reference & is used instead, but & is defined as being &.

This code will resolve the character references in an HTML/XML text fragment.
Code:
NSXMLNode *node = [[[NSXMLNode alloc] initWithKind:NSXMLTextKind] autorelease];        
[node setStringValue:@"www.testing.aspx?username=123[plain]&[/plain]pwd=456"
   resolvingEntities:YES];
NSString* url = [node stringValue];
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.