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