The solution is to encode symbols into special character set on the client side and decode them on the server side.
NSURL and NSRequest fails in php with UTF-8 through objective-c
-
15-06-2023 - |
Question
I have a php script that enters a url string into a mySQL database. The url is sendt by an iphone app written in objective-c. It works fine except when the url code contains a scandinavian letter like ø, æ, or å. Example:
NSString *myString =[NSString alloc]initWithFormat:@".../myphp.php?Name=Strøm];
NSURL *myUrl =[NSURL URLWithString:[myString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog (@"String: %@",mysTring);
NSLog (@"URL: %@",myUrl);
NSMutableURLRequest *req=[NSMutableURLRequest requestWithURL:myUrl];
NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:req delegate:self startImmediately:YES];
Output:
String .../myphp.php?Name=Strøm
URL: .../myphp.php?Name=Str%C3%B8m
Problem: When the URL is delivered by the app, "ø" is turnded into "ø" in the mySQL database. When the URL is entered into the url field of a browser, the "ø" is written correct.
Somehow, I think something is wrong with the urlrequest. Is there a way to fix this problem?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow