I am developing an application in which I need to encode URL. I tried using http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/ and
[NSString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]] but its not working out for me. Is there any alternate URL encoder class for iphone like java?
How to achieve it?? Thanks in advance...
Try the following for URL encoding :
NSString *url= [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)originalpath, NULL, CFSTR(";:"), kCFStringEncodingUTF8) autorelease];
You can refer to this post to find your solution.
You can try the following for URL encoding:
`NSString *urlString = [NSString stringWithFormat:#"http://www.abc.com/parsexml.aspx?query=%#", [searchBar.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];`
Related
If I have a Url as NSString like:
http://www.abarid.com/Mobile_apps/products_thumb/Untitled2.png
and I want to get only (Untitled2) as another NSString, how to do that in iPhone code?
Thanks in advance.
NSString* theExtractedName = [[yoururl lastPathComponent] stringByDeletingPathExtension]
The lastPathComponent call will return "Untitled2.png", and the stringByDeletingPathExtension will remove the ".png"
Use instance method lastPathComponent.
I try to display an image with a URL source in an iOS application, but it doesn't show up.
The url of the image is live example path.
When escaping this string using the following Objective-C code:
NSString *url= [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)originalpath, NULL, CFSTR("øæ"), kCFStringEncodingUTF8) autorelease];
the result is (with encoding of øæ) : live xml path
All my files where the URLs are stored use text encoding (UTF-8).
How do I escape the URL in a right way, such that the image will be displayed?
don't go for ascii encoding try it
NSString *URLString = [yourImagepath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:URLString];
I hope it will help you out.
I believe you need to escape your url-string, before using it as an url...
NSString *URLString = [yourImagepath stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:URLString];
Had the same problem on iOS with German umlauts. The NSURL category NSURL+IFUnicodeURL solved the problem for me, don't get scared by the amount of C code in there, it's well-hidden :)
I am parsing xml through my aspx page to my iphone app. I am doing this way to get XML data from url and append into NSData like this below.
NSString *urlString =
[NSString stringWithFormat:#"http://www.abc.com/parsexml.aspx?query=%#",
searchBar.text];
NSURL *url = [NSURL URLWithString:urlString];
error comes when my urlString has whitespace between characters e.g(http://www.abc.com/parsexml.aspx?query=iphone 32gb 3gs)
please help me. What should i do to resolve this issue.
Use NSString's -(NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding; to encode the url request data.
Check the doc here.
NSString *urlString =
[NSString stringWithFormat:#"http://www.abc.com/parsexml.aspx?query=%#",
[searchBar.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
You Can Use %20 Instead of Space Remove Space By %20 in your URL String
Hope It Will Help You..
Have a slight problem. Trying to post XML to a server. To do this, I have to encode the XML string in URL format.
NSString *encodedString = [NSString stringWithFormat:#"xmlValue=%#",[post stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]];
That's what I have and it works for all the characters EXCEPT the '='. This does not get converted to %3D. Has anyone else ever had this problem before? Am I specifying the wrong encoding type? I have tried "NSUTF8StringEncoding" as well.
This is a little piece of the XML string:
#"<xml-service application=\"broadcast\" type=\"REQUEST\"><identity token=\"xxxxxxxx\".....
Any help would be appreciated! Thanks
This should solve your problem:
NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)#"!*'();:#&=+$,/?%#[]",
kCFStringEncodingUTF8 );
Source
You can try this. I found this helpful.
NSString *sampleUrl = #"http://www.google.com/search.jsp?params=Java Developer";
NSString* encodedUrl = [sampleUrl stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding];
I'm creating a link to open my App and pass some data in the URL.
When I add the query parameter ? my link get broken.
NSData *fileData = [NSData dataWithContentsOfFile:dataFilePath];
NSString *encodedString = [GTMBase64 stringByWebSafeEncodingData:fileData padded:YES];
NSString *urlString = [NSString stringWithFormat:#"myApp://localhost/backup?%#",
encodedString];
the link is quite long, but also a shorter one doesn't work:
myApp://localhost/backup?PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48bG9jPjxpbmdyZWRpZW50VHlwZS
and when the e-mail appears in the iPhone, only this is underlined and act as a link:
myApp://localhost/
Adding the query as NeilInglis suggest it doesn't work also, the link is broken at same place.
NSString *urlString = [NSString stringWithFormat:#"myApp://localhost/backup?query=%#",
encodedString];
The Html is ON or OFF, it doesn't affect.
If I enocode the URL it also doesn't work ...
Don't know what I can try next ...
any ideas ?
thanks ...
regards,
r.
Try mapping the query parameter to a name.
#"myApp://localhost/backup?queryParamName=%#