문제

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?

도움이 되었습니까?

해결책

The solution is to encode symbols into special character set on the client side and decode them on the server side.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top