Using initWithRequest:delegate:
of NSURLConnection
starts an asynchronous download, so it returns immediately and executes straight away.
response
is always nil
because you just defined it and then logged it without ever setting it to anything. That needs to be done in the connection:didReceiveResponse:
delegate method.
Where you do if(conn){
, the conn
existing doesn't mean the connection was successful, it just means that the connection could be created (basically, you didn't supply an invalid request). You don't know whether it's going to work yet.
Implement the delegate methods from NSURLConnectionDelegate_Protocol
(and NSURLConnectionDataDelegate
) to get access to the response and downloaded data (when it becomes available).