Escapar de caracteres NSURL
Frecuentes
Visto 245 veces
1
Im working on a library for the LinkedIn api. In some cases i need to send a escaped url. Im using CFURLCreateStringByAddingPercentEscapes for this task and seems to work find for me.
Why this is not a valid URL?
NSURL *base = [NSURL URLWithString:@"https://api.linkedin.com"];
NSString *r = @"/v1/people/url={www.linkedin.com%2Fin%2Fbilby91}";
NSURL finalUrl = [NSURL URLWithString:r relativeToURL:base];
finalUrl is always null and i think is correctly escaped. The original url is www.linkedin.com/Fin/bilby91
Muchas Gracias
3 Respuestas
0
Agrega esto
NSString *r = [@"/v1/people/url={www.linkedin.com%2Fin%2Fbilby91}" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
respondido 27 nov., 13:07
0
The problem was that this characters '{'
'}'
need to be encoded even though they are not reserved. Some characters including the ones before are considered unsafe and can be misunderstood in the url so its better to always encode them.
respondido 27 nov., 13:19
-1
[NSString stringWithFormat:@"%@",[r stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
use this, this may help u
respondido 27 nov., 13:07
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas objective-c escaping nsurl or haz tu propia pregunta.
There is no point to the
stringWithFormat:
portion of this code - mike abdullah