I am sending HTTP post request with NSURLConnection synchronous request as soon as the user signs in to a server. The cookies are used for authentication and am not setting any cookie as header.
case 1: I receive a success response when I launch the application for the first time and sign in.
case 2: Later, when I quit the application with signed in state and later relaunch the application, sign out and sign in again, i receive -1012 error.
case 3: The error is not occurring on logging out in the same session as I logged in. For instance, if I sign in on app launch and sign out, then quit the app, again relaunch and sign in, I receive a success response.
Please help me with second case.
My post request is as follows:
// perform eHTTPPost request with header
- (NSData *)doPostRequest:(NSURL *)serverURL
data:(NSData *)postData
headerContentType:(NSString *)contentType
{
NSData *returnData;
_connectionException = nil;
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long) [postData length]];
HTTPClient *client = [[HTTPClient alloc] initWithRequestType:eHTTPPOST
withServerURL:[serverURL absoluteString]
andPath:nil
andQueryString:nil
andData:postData];
[client setRequestDataContentType: contentType];
[client setRequestDataContentLength:postLength];
[client setShouldZipEncode:NO];
if([client sendRequest]){
returnData = [client responseData];
NSError *parseError = nil;
NSString *responseDataString = [NSString stringWithUTF8String:[returnData bytes]];
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:returnData
options:NSJSONReadingAllowFragments
error:&parseError];
NSLog(@"Set attributes Response Dict: %@",responseDict);
}else{
//Handle error
_connectionException = [client responseException];
NSLog(@"HTTP error : %@", [client responseException].reason);
}
return returnData;
}