2

Someone knows why I'm getting null in this code?

NSURLRequest *requisicao = [NSURLRequest requestWithURL:
                               [NSURL URLWithString:URLAddress]];

When I debug this line and preview the content of this variable, I receive null -
"<NSURLRequest (null)>"

My URLAddress is a request for a JSON service.

nobu86
  • 55
  • 9

1 Answers1

6

It's most likely null because URLAddress contains characters that need to be percent-escaped (which is what the URLWithString method needs).

Try using stringByAddingPercentEscapesUsingEncoding:

NSURLRequest *requisicao = [NSURLRequest requestWithURL:
    [NSURL URLWithString:
        [URLAddress stringByAddingPercentEscapesUsingEncoding:
                        NSUTF8StringEncoding]]];    

However, see this answer by Dave DeLong which points out limitations of stringByAddingPercentEscapesUsingEncoding and alternatives to it.

Community
  • 1
  • 1