URL encoding iOS NSURL error

前端 未结 2 1386
暗喜
暗喜 2021-01-29 06:42

URL which opens in Firefox,Chrome browsers on desktop, doesn\'t open in WebView on iPhone. This URL is supposedly accessing a GET request. When creating the NSURL without perce

2条回答
  •  甜味超标
    2021-01-29 07:21

    Sometimes URL encoded format already except for the é-character which should probably be encoded as %c3%a9. Desktop browser is quite liberal with invalid URLs, thats why it works in Safari etc. So if you have a NSString and you want to convert it into a proper URL encoding then use the below method of NSString class.

    NSURL* url = [NSURL URLWithString:[strURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

提交回复
热议问题