Escapar de caracteres NSURL

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:@""];
NSString *r = @"/v1/people/url={}";
NSURL finalUrl = [NSURL URLWithString:r relativeToURL:base];

finalUrl is always null and i think is correctly escaped. The original url is

Muchas Gracias

preguntado el 27 de noviembre de 13 a las 05:11

3 Respuestas

Agrega esto

NSString *r = [@"/v1/people/url={}" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

respondido 27 nov., 13:07

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

[NSString stringWithFormat:@"%@",[r stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

use this, this may help u

respondido 27 nov., 13:07

There is no point to the stringWithFormat: portion of this code - mike abdullah

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.