tags:

views:

395

answers:

2

I am using the example shown here - listing's 1-5 to request the content of a URL and everything is working perfectly. Now my problem is, while the first request is sent off, I want to request content from a second web page, my problem is, even if I duplicate everything there for a second request and connection, and create another variable for NSMutableData that should hold the second request's data, I am only getting the second requests data filled into *receivedData (i.e. the original first requests NSMutableData)

Its like the moment I add code for a second request, only the second request is executing...

Does anyone know how to modify the code in the linked example so I can issue two separate requests?

Disclaimer: learning objective-C now, my background is C#/VB.

+1  A: 

If you are using "self" as the delegate for both requests, then you'll be getting callbacks for both of the requests and you are most likely only writing the bytes into a single receivedData object. What you need to do is either create a new class to act as the delegate and create a new instance of the class for each request, or if you want to continue using "self" as the delegate make sure you take a look at the "connection" parameter passed into the delegate methods. That will indicate which connection the callback belongs to, allowing you to write the data to the appropriate receivedData object.

Marc Novakowski
+1  A: 

Take a look here. There you'll find the examples how to manage this

kompozer