Handling 404 error problems in the WebView Delegate in iPhone sdk - iphone

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.

Related

NSURLConnection delegate methods not giving the response immediately

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.

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.

ASIHTTPRequest video download failed sometimes and sometimes not?

In my project i need to download nearly 50 videos from cloud, i download it using ASIHTTPRequest in Asynchronous way by handling responses using success and failure delegate methods.
When video download is success the corresponding success delegate method is called and i got status code 200, if partial download i got status code 206 in same delegate method and if file not found i got status code 404 on success delegate method.
If request itself failed it hit the corresponding failure delegate method, some times it return status code 200 in failure delegate method. But status 200 for success only.
Another thing i need to make video download complete without any failure(How can i handle this).If any one knows help me out.
Thanks

Read the page header from a UIWebView

I'm looking for a solution for reading the http status code with a UIWebView.
I have found this page on the topic How do I get the last HTTP Status Code from a UIWebView? but i cannot use AsiHttpRequest in my case.
Si I was wondering if somebody have found a solution since 2009, and if something similar to NSLog(#"Status code = %#",[webView stringByEvaluatingJavaScriptFromString:#"document.status"]);
could possibly work.
Thanks,
I don't think you can get it from the UIWebView, but I think it would work to have the result of an HTTP request put into an NSString, then parse the status code out of the header part of that string, thing feed that string to a UIWebView.
See the NSURL Class Reference and the URL Loading Programming Guide.
A possible alternative would be to implement an HTTP proxy directly inside your App, then feed a localhost URL to UIWebView. Your proxy would just make an HTTP connection with the web server and sit passively by while UIWebView drives the HTTP protocol. You then snoop on the incoming data before passing it on to UIWebView from your proxy. That would avoid the need to buffer the whole page in an NSString before feeding it to your UIWebView.

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.