1

This is how I am using the NSUrlConnection

- (void) serverHttpRequest:(NSString*)data
                        forUrl:(NSString*)Url
                       withTag:(NSString*)tag
                      httpType:(NSString *)type
                   forThisTime:(int)tryTime
           withTimeOutInterval:(float)interval
    {


        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", Url]];

        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url
                                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                              timeoutInterval:interval];

        [theRequest setHTTPMethod:type];
        [theRequest setValue:@"application/x-www-form-urlencoded;charset=utf-8" forHTTPHeaderField:@"Content-Type"];


        NSString *postData = data;

        NSString *length = [NSString stringWithFormat:@"%d", [postData length]];
        [theRequest setValue:length forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];

        self.theConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
        [self.theConnection start];

    }

But it fails to hit the server almost 50% time when called repeatedly. Why this is happening. The call frequency is per second. The url is not same for all requests and the client is required to fetch data from multiple servlets on java server with Http POST request. May be something wrong configured on server side.

Possibly the problem is not on client side because when i Ran the same code on two different devices they both received error response at the same time. Also the devices are connected to internet via a proxy server. The error code is HTTP 503 . I know this error is shown when the server is overloaded or refused to respond, but it was working fine as it was receiving requests from other clients. I have implemented basic JAVA servlets and connecting it to MySql database using JDBC driver. If anyone could tell me how what configuration changes should i do on the server or client. THankyou

Jain
  • 854
  • 5
  • 15
  • possible duplicate of [NSURLConnection sendAsynchronousRequest:queue:completionHandler: making multiple requests in a row?](http://stackoverflow.com/questions/9409211/nsurlconnection-sendasynchronousrequestqueuecompletionhandler-making-multiple) – aug2uag Sep 14 '15 at 08:21
  • I have edited this question. Also the problem is not on the client side. – Jain Sep 16 '15 at 04:35

1 Answers1

0

The only way I know of to determine why a server is sending back a 503 response is to check in the server's logs and see what went wrong. Either that or check the proxy server's logs.

dgatwood
  • 10,129
  • 1
  • 28
  • 49