Note that there are some explanatory texts on larger screens.

plurals
  1. POCocoa: NSURLConnection not attempting an HTTP Request
    text
    copied!<p>I've had significant success with NSURL, NSURL[Mutable]Request, NSURLConnection with my iPhone applications. When trying to compile a stand alone Cocoa application, 10 line program to make a simple HTTP request, there are zero compiler errors or warnings. The program compiles fine, yet the HTTP Request is never made to my web server (I'm running a tcpdump and watching Apache logs in parallel). When I run very similar code in an iPhone app, essentially copy/pasted as evil as that is, all works golden. </p> <p>I kept the code for the 'obj' declaration in the delegate to NSURLConnection out of this code snippet for the sake of simplicity. I'm also passing the following to gcc:</p> <p>gcc -o foo foo.m -lobjc -framework cocoa</p> <p>Thanks for any insight.</p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; int main (int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString * urlstr = @"http://tmp/test.php"; [NSApplication sharedApplication]; NSObject *obj = [[NSObject alloc] init]; NSURL *url = [NSURL URLWithString: urlstr]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; if([request isKindOfClass:[NSMutableURLRequest class]]) NSLog(@"request is of type NSMutableURLRequest"); [request setHTTPMethod:@"GET"]; [request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:obj startImmediately:YES]; if(connection) NSLog(@"We do have a connection."); [pool release]; return 0; </code></pre> <p>} </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload