ggarber
ggarber

Reputation: 8360

Sending simultaneous NSURLConnection requests

Is it possible to make simultaneously two requests in parallel to the same server using NSURLConnection?

I'm trying to do it, and it looks like the second request do not start until the first one finishes.

Upvotes: 3

Views: 1753

Answers (3)

evgen_povt
evgen_povt

Reputation: 21

The second request seems to be waiting the first one if cookies exist. I believe it's done to send actual cookies in the second request because they can be modified in the response for the first request.

You can turn handling of cookies off by setting a property HTTPShouldHandleCookies to NO.

Upvotes: 1

catlan
catlan

Reputation: 25256

If you use the sync version of NSURLConnection

+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error

you need to start two threads to get the behavior you want, you can do this my moving the download in a own method and call this over:

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg

The other way would be to use Asynchronously version of NSURLConnection, see docu.

Upvotes: 2

leonho
leonho

Reputation: 3543

You need to create two NSURLConnection objects.

Upvotes: 1

Related Questions