I am facing an issue in basic authentication ,for which I am not able to understand the reason why this issue is there.
In basic authentication I am getting response code 200 i.e authentication successful,but sometime I am not getting response data properly in iOS application.
If I paste request url in browser(even in iPhone safari browser also), I am always getting the response.But why I am not always getting the response in iOS application.
I have gone through many other issues in google and stack overflow for example link1, but no luck.
My code is as below:
//in implemetation file
-(void)basicAuthentication{
.
.
NSURL *url = [NSURL URLWithString:authenticationUrl];
NSMutableString *loginString = (NSMutableString*)[@"" stringByAppendingFormat:@"%@:%@", @"username",@"password"];
NSString *authHeader = [@"Basic " stringByAppendingFormat:@"%@", loginString];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setURL:url];
[request setHTTPMethod:@"GET"];
[request addValue:authHeader forHTTPHeaderField:@"Authorization"];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
myData = [[NSMutableData data] retain];
}
//Delegate method called when the connection receives data
/*
* Callback, called when ever there is more response data read
*/
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[myData appendData:data];
}
//in .h file
@interface TestConnectionManager : NSObject <UIAlertViewDelegate,NSURLConnectionDelegate>{
id <TestConnectionManagerDelegate>delegate;
NSMutableData *myData;
.
.
.
}
I have faced near about similar issue and I got an temporary solution which I am going to suggest. But I am not sure that how much this will be helpful for your case.
I have putted log messages of data received inside
didReceiveDatamethod. If you can’t put the received data you can take the log of data length.