NSURLConnection delegate methods not giving the response immediately - iphone

Hi in my application I am using NSURLConnection delegate metods to get a response from the server.Here what is happening is when ever I send a request to the server for the first time I am getting response immediately.After that first request if I send same request to the server again immediately I am getting the response as null. But if i leave the ipad aside after sometime I am getting the response can you please let me know is there any time limit needed between the requests while sending to the server using NSURLConnection delegate methods.Please help me to resolve this issue.
Thanks in advance.

Related

AFNetworking and Network Errors

I am using the AFNetworking framework to make several JSON web request.
During development if I fail to provide a required parameters or the Service developers have broken something :-) i receive a 500 error
The Error block of AFJSONRequestOperation is correctly catching it. However i cannot see the page body because AfNetworking is cancelling the request as soon as the error code in the head is received.
Is there some work around. I would like to spit out the response body to the log.
Use the responseData or responseString property from the operation that's passed into the failure block.
You'll need to add the http Code 500 to the acceptable status codes and filter it on the success callback. There you will have a responseObject.

iOS - RestKit and sending a post request to the server?

When I try to post an object using RestKit I get the following error.
"Cannot send a request that is loading or loaded without resetting it first."
What does it mean?
How can I reset a request?
Without posting a code, it is hard to say where the error is, but:
This error occurs, when either _isLoading or _isLoaded is set to NO. You could try to reset your request before sending it using [myRequest reset];.

Handling 404 error problems in the WebView Delegate in iPhone sdk

I am working with WebView based application, in that I had a problem with http 404 errors when I tried to load an url. I just want to show an alert when this happens. Can you guys please suggest me that how to trigger it and is there are any delegate methods fired when this happens?. Please suggest.
Thanks in adv,
S.
You can not check the status code for UIWebView requests. I rarely use webviews to do requests and when I do I don't care what the status codes are. I usually use NSURLConnection or ASIHTTPRequest to do requests. If you have to know the status of the http request, then do it using an NSURLRequest object and set the delegate to receive the response status code.

NSURLConnection "lost network connection" error?

I am developing an app that will upload the image from the iphone to a server. In server side there is a php program to handle the uploaded image. I am using the NSURLConnection with the Post method and have set the post body of the request. When I upload the image, I could see the image uploaded 3 times(in the server), but after sometime didFailWithError: is called stating that "lost network connection". What could be the reason for this? My doubt is that why is that image is uploaded multiple times? I have set the timeout of the request to 3600.0
Any help is appreciated.
Thanks
In my case, i have forgot to set method to POST like this:
[aRequest setHTTPMethod:#"POST"];
Hope it helps
How does your server respond to the upload? What status does it return to the client? If it accepts the image then resets the connection without replying to the POST request, you'll see the behaviour you've described.

NSMutableURLRequest: didReceiveData not called at the first time

I've dug through a lot of topics regarding didReceiveData: method not being called - the solution is to set appropriate cachePolicy and implement willCacheResponse delegate method.
So I did, now I get didReceiveData message each time anything comes from the server.
Unfortunately I don't get didReceiveData the very first time the server responds.
In other words, the first time I get "didReceiveData" message there are 2 response objects in the "data" parameter. Every response from the server following that moment is OK.
Any help?
Just needed a clarification; Are you using any threading in your application?
If Yes, then the thread which creates the connection should receive the response from the server. The other threads will not identify the response which is returned for some other thread.