开发者

vertical pipe symbol not being detected in NSURL

开发者 https://www.devze.com 2023-03-08 21:06 出处:网络
I\'m trying to place a search in google dictionary but the url contains a vertical pipe/bar | My code just fails to load the site

I'm trying to place a search in google dictionary but the url contains a vertical pipe/bar | My code just fails to load the site

 //http://www.google.com/dictionary?aq=f&langpair=en|en&q=test+test+test&hl=en


if ([mySearchEngineName isEqualToString:@"Google Dictionary"]){
        NSLog(@"Currently searching %@ using %@", mySearchString, mySearchEngineName); 

        NS开发者_如何学CString *mutateSearchString = [mySearchString stringByReplacingOccurrencesOfString:@" " withString:@"+"];
        NSString *searchURL =[NSString stringWithFormat:@"http://www.google.com/dictionary?aq=f&langpair=en|en&q=%@&hl=en", mutateSearchString];
        NSURL *url = [NSURL URLWithString:searchURL];
        [webBrowser loadRequest:[NSURLRequest requestWithURL:url]];
    }

using %7C did not work either..

NSString *searchURL =[NSString stringWithFormat:@"http://www.google.com/dictionary?aq=f&langpair=en%7Cen&q=%@&hl=en", mutateSearchString];


Consider encoding your URL using something like:

NSURL *url = [NSURL URLWithString:[searchURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; 

rather than manually doing it yourself. Perhaps there is some characters in your mySearchString NSString that also needs encoding. Run this encoding after you have stringWithFormat'd the full URL together.

0

精彩评论

暂无评论...
验证码 换一张
取 消