Ho un NSURL della formaCome si aggiunge qualcosa come "? X = 123" a un NSURL?
"http://abc.def.com:1234/stuff/"
e voglio aggiungere ad essa in modo che l'URL finale è come questo
"http://abc.def.com:1234/stuff/?x=123".
Ma se faccio questo
url = [NSURL URLWithString:@"http://abc.def.com:1234/stuff/?"];
url = [url URLByAppendingPathComponent:@"x=123"];
Poi il risultato è
http://abc.def.com:1234/stuff/x=123?
(è lo stesso risultato se si utilizza URLByAppendingPathExtension).
Ma se faccio questo
url = [NSURL URLWithString:@"http://abc.def.com:1234/stuff/?"];
url = [url URLByAppendingPathComponent:@"x=123"];
Poi il risultato è
http://abc.def.com:1234/stuff/%3Fx=123
(anche lo stesso risultato se URLByAppendingPathExtension è utilizzato).
Nessuno dei due è quello che sto cercando. Come posso ottenere un risultato finale di "http://abc.def.com:1234/stuff/?x=123"?
Quando sto provando sopra metodo mostrato Il mio url non sta arrivando corretto appare invertito come "? X = 1 & y = 2 & z = 3 http://foo.com/bar/baz" si prega di fornire qualche soluzione Se avete per questo. Grazie –
@jalakpatel 'url.description' restituisce'? X = 1 & y = 2 & z = 3 - http: // foo.com/bar/baz', quindi 'NSLog (@" URL:% @ ", url)' metterà "URL:? x = 1 & y = 2 & z = 3 - http://foo.com/bar/baz" 'nel debugger. Se vuoi visualizzare l'URL completo, usa "url.absoluteString". Ad esempio, 'NSLog (@" URL:% @ ", url.absoluteString)' inserirà '" URL: http://foo.com/bar/baz?x=1&y=2&z=3 "' nel debugger. –
@jalakpatel NOTA: 'url.description' è solo a scopo di visualizzazione. Passando 'url' a qualsiasi metodo che prende un URL andrà nella posizione corretta. –