ASIHTTPRequest synchronously

I have an iPhone app that uses ASIHTTPRequest to communicate with the REST service on my server. When I run the simulator, it works fine, but when I sit on the phone, I get strange behavior.

The first time I click the button that initiates the request, I immediately return the results, and everything is in order. From now on, when I press the button to start the connection, it takes about 2-3 minutes to connect. It seems that the ASIHTTPRequest, which I started first (and from which I already got the correct results), did not end. Is there any magic I need to use to complete the initial request before starting the next? I assumed that since the -start method was returned, and I have results from the server, that the original request was completed, and I could run another.

Any ideas?

thanks

- Steve

+4
source share
2 answers

You should not call the -start method, it belongs to NSOperation. The ASIHTTPRequest interface is either -startSynchronous or -startAsynchronous.

However, it is highly recommended that you use an asynchronous call otherwise, your main thread (i.e., the user interface) will be blocked.

From the ASIHTTPRequest documentation [1]

In general, you should use asynchronous requests, preferably synchronous requests. When you use ASIHTTPRequest synchronously with the main thread, the user of your application interface will close and become unusable during the request. Synchronous requests are really suitable for software without a UI (for example, a script that is run from a terminal), or if you use a request from a separate thread that you support (perhaps from within, for example, your own NSOperation).

[1] http://allseeing-i.com/ASIHTTPRequest/How-to-use

+2
source

Steve. What you described is a common problem that arises if requests try to keep a persistent connection. Try it:

[request setShouldAttemptPersistentConnection:NO]; 
+6
source

All Articles