How to improve memory management when doing low level http work - objective-c

I'm starting to cleanup an older prototype I worked on and it's doing a great deal of low level http work. The problem I'm having is how and when to do a release inside the "connectionDidFinishLoading" method below. I have some items only created inside the if but when I release them before the method call I get several BAD ACCESS errors and thought to ask how I should be doing memory management in this scenario.
- (void)searchForNewHats:(HatViewController *)hatVwController
{
responseData = [[NSMutableData data] retain]; //responseData is a property that I retain - fyi
hatController = hatVwController; //hatController is a property that I retain - fyi
NSURL *url = [NSURL URLWithString:#"http://localhost/jsondata"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:#"GET"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray *json = [responseString JSONValue];
if (json != NULL) {
NSArray *items = [json valueForKeyPath:#"d"];
HatParseJson* hatParseJson = [[HatParseJson alloc] init];
NSArray* hatz = [hatParseJson parseJson:items];
NSMutableArray* newHats = [[NSMutableArray alloc] init];
NSUInteger i, count = [hatz count];
for (i = 0; i < count; i++) {
Hat* obj = [hatz objectAtIndex:i];
[newHats addObject:obj];
//[obj release]; this blows up for example ...
}
[hatParseJson release];
[hatController newHatJsonFinished:newReleases];
}else {
[hatController newHatJsonFinished:nil];
}
[responseString release];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
}
Thank you in advance

some updates and comments inline:
- (void)searchForNewHats:(HatViewController *)hatVwController
{
assert(0 == responseData);
responseData = [NSMutableData new];
assert(0 == hatController);
self.hatController = hatVwController;
NSURL * url = [NSURL URLWithString:#"http://localhost/jsondata"];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:#"GET"];
/* the delegate is retained in iOS, but not necessarily in OS X so... maybe you want to make connection an ivar of self? */
NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
/* don't you want to hold on to this? */
[connection release], connection = 0;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)inConnection {
if (ConnectionIsAnIvar) {
if (self.connection != inConnection) {
assert(0 && "connection delegate messages sent to wrong instance. threading issue or worse?");
return;
}
}
else {
[connection release];
}
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray *json = [responseString JSONValue];
if (json != NULL) {
NSArray *items = [json valueForKeyPath:#"d"];
HatParseJson* hatParseJson = [[HatParseJson alloc] init];
NSArray* hatz = [hatParseJson parseJson:items];
NSMutableArray* newHats = [[NSMutableArray alloc] init];
/* why not simply:
NSMutableArray* newHats = [hatz mutableCopy];
*/
NSUInteger i, count = [hatz count];
for (i = 0; i < count; i++) {
Hat* obj = [hatz objectAtIndex:i];
[newHats addObject:obj];
/* [obj release]; this blows up for example ... */
/* >> it should blow up. objectAtIndex: uses a get, not retain or copy */
}
[hatParseJson release];
[hatController newHatJsonFinished:newReleases];
}
else {
[hatController newHatJsonFinished:nil];
}
[responseString release];
}

[obj release] is a wrong thing to do because you are just adding objects from one array to another. Instead you should release newHats when done because you explicitly allocate it with alloc.

Related

Objective-C how to convert nsdata from web service to nsarray

How do i convert id to an array?
I have an apple app that talks to a server.
Issue i have is the app returns the data in the form of id however i need to convert this to an array as the actual returned data looks like the following.
[["30","2",1],["15","67",1],["30","4",1]]
It is actually the output from a mysql server
The actual app code looks like the following
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"blah blah"]];
NSURL_Layer * connection = [[NSURL_Layer alloc]initWithRequest:request];
[connection setCompletitionBlock:^(id obj, NSError *err) {
if (!err) {
//Need to convert the id to nsarray here, dunno how
} else {
//There was an error
}
}];
[connection start];
The NSURL.h
-(id)initWithRequest:(NSURLRequest *)req;
#property (nonatomic,copy)NSURLConnection * internalConnection;
#property (nonatomic,copy)NSURLRequest *request;
#property (nonatomic,copy)void (^completitionBlock) (id obj, NSError * err);
-(void)start;
NSURL.m
-(id)initWithRequest:(NSURLRequest *)req {
self = [super init];
if (self) {
[self setRequest:req];
}
return self;
}
-(void)start {
container = [[NSMutableData alloc]init];
internalConnection = [[NSURLConnection alloc]initWithRequest:[self request] delegate:self startImmediately:YES];
if(!sharedConnectionList)
sharedConnectionList = [[NSMutableArray alloc] init];
[sharedConnectionList addObject:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[container appendData:data];
}
//If finish, return the data and the error nil
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
if([self completitionBlock])
[self completitionBlock](container,nil);
[sharedConnectionList removeObject:self];
}
//If fail, return nil and an error
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
if([self completitionBlock])
[self completitionBlock](nil,error);
[sharedConnectionList removeObject:self];
}
Update:
i have added
NSURL_Layer * connection = [[NSURL_Layer alloc]initWithRequest:request];
[connection setCompletitionBlock:^(id obj, NSError *err) {
if (!err) {
NSError* error;
NSArray* array = [NSJSONSerialization JSONObjectWithData:obj options:NSJSONReadingAllowFragments error:&error];
} else {
//There was an error
}
}];
[connection start];
but returns error
error NSError * domain: #"NSCocoaErrorDomain" - code: 3840
_userInfo NSDictionary * 1 key/value pair
[0] (null) #"NSDebugDescription" : #"Invalid value around character 0."
Update: I put
NSLog(#"Data as string:%#", [[NSString alloc]initWithData:obj encoding:NSUTF8StringEncoding]);
which gave me a strange feedback. As a result i looked at my url request full code is below.
NSString *post = [NSString stringWithFormat:#"unique_id=%#&unique_password=%#",ServerUniqueID,ServerPassword];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%lu", (unsigned long)[post length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"blah blah"]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:postData];
NSURL_Layer * connection = [[NSURL_Layer alloc]initWithRequest:request];
[connection setCompletitionBlock:^(id obj, NSError *err) {
if (!err)
{
NSError* error;
NSArray* array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithData: obj] options:NSJSONReadingAllowFragments error:&error];
NSLog(#"Data as string:%#", [[NSString alloc]initWithData:obj encoding:NSUTF8StringEncoding]);
int temp = array.count;
}
else
{
//There was an error
}
}];
[connection start];
if i remove
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:postData];
it works
if its in it dosn't so i have a whole new issue to look into.
you save the bytes into a container variable, alas the id infact NSData
(note id is just a 'wildcard pointer' that means ANY objC object)
so your id is NSData and from what you show it seems to be 3 json arrays... but no real JSON... (["30","2",1]["15","67",1]["30","4",1] isn't anything)
EITHER make the server send you JSON and THAT you can parse into a dictionary/array using NSJSONSerialization
OR write a custom separator to convert the data

NSURLConnection Delegates Issue

I have a problem with NSURLConnection delegate. Simply I need to get a result from the server based on that result, I will do some stuff.
The problem is :
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
Method is calling at last and I am receiving answer in this part. Then I cannot use the result that came from the server.
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(#"DidfinishLaunch started");
self.json = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:nil];
if (!self.parsedJsonContent) {
self.parsedJsonContent = [[NSMutableArray alloc]init];
}
for (int i=0; i<self.json.count; i++) {
NSString *result = [self.json objectAtIndex:i];
self.user.result = result;}
}
}
and when I want to use the value of result in MainViewController:
NSLog(#"result: %#",[self.jsonProcess GetJsonResultForLogin]);
it comes empty. So how am I going to grab the value of result, couse the value of result is filling in connectionDidFinishLoading which is the last method that called.
Maybe you need to grab the data received in:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
and just use the
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
to know when the connection ends.
SPJsonProcess.m
-(void)OpenAConnection:(NSString *)URL appendStringURL:(NSString *)appendURL
{
NSMutableString *postUrl = [NSMutableString stringWithString:URL];
if (![appendURL isEqualToString:nil]) {
[postUrl appendString:appendURL];
}
NSURL *jsonUrl = [NSURL URLWithString:postUrl];
NSData *data = [NSData dataWithContentsOfURL:jsonUrl];
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:jsonUrl];
connection = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[connection start];
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(#"DidfinishLaunch started");
self.json = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:nil];
if (!self.parsedJsonContent) {
self.parsedJsonContent = [[NSMutableArray alloc]init];
}
for (int i=0;i < self.json.count; i++) {
NSString *result = [self.json objectAtIndex:i];
self.user.result = result;
}
}
-(NSString *)GetJsonResultForLogin
{
return self.user.result;
}
LOGIN VIEW CONTROLLER
>-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
>[self.jsonProcess OpenAConnection:#"My Domain adress" appendStringURL:appendString];
>NSLog(#"Method invoked");
>NSLog(#"result: %#",[self.jsonProcess GetJsonResultForLogin]);
result as a log comes null. But in didFinishLoading method gets result from server without a problem.

how can I use NSURLConnection Asynchronously?

I am using this code to load data to my App, can you tell me how can I make this asynchronously?
NSMutableURLRequest *request2 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request2 delegate:self];
if (connection)
{
NSLog(#"NSURLConnection connection==true");
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&response error:&err];
self.news =[NSJSONSerialization JSONObjectWithData:responseData options:nil error:nil];
NSLog(#"responseData: %#", self.news);
}
else
{
NSLog(#"NSURLConnection connection==false");
};
I think you should be bothered reading the documentation. There's a sendAsynchronousRequest:queue:completionHandler: method.
Create the connection with initWithRequest:delegate:startImmediately:, set yourself as its delegate and implement the delegate methods.
Block code is your friend. I have created a class which does this for you
Objective-C Block code. Create this class here
Interface class
#import <Foundation/Foundation.h>
#import "WebCall.h"
#interface WebCall : NSObject
{
void(^webCallDidFinish)(NSString *response);
}
#property (nonatomic, retain) NSMutableData *responseData;
-(void)setWebCallDidFinish:(void (^)(NSString *))wcdf;
-(void)webServiceCall :(NSString *)sURL_p : (NSMutableArray *)valueList_p : (NSMutableArray *)keyList_p;
#end
Implementation class
#import "WebCall.h"
#import "AppDelegate.h"
#implementation WebCall
#synthesize responseData;
-(void)setWebCallDidFinish:(void (^)(NSString *))wcdf
{
webCallDidFinish = [wcdf copy];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
int responseStatusCode = [httpResponse statusCode];
NSLog(#"Response Code = %i", responseStatusCode);
if(responseStatusCode < 200 || responseStatusCode > 300)
{
webCallDidFinish(#"failure");
}
[responseData setLength:0];
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(#"WebCall Error: %#", error);
webCallDidFinish(#"failure");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
response = [response stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
webCallDidFinish(response);
}
-(void)webServiceCall :(NSString *)sURL_p : (NSMutableArray *)valueList_p : (NSMutableArray *)keyList_p
{
NSMutableString *sPost = [[NSMutableString alloc] init];
//If any variables need passed in - append them to the POST
//E.g. if keyList object is username and valueList object is adam will append like
//http://test.jsp?username=adam
if([valueList_p count] > 0)
{
for(int i = 0; i < [valueList_p count]; i++)
{
if(i == 0)
{
[sPost appendFormat:#"%#=%#", [valueList_p objectAtIndex:i],[keyList_p objectAtIndex:i]];
}
else
{
[sPost appendFormat:#"&%#=%#", [valueList_p objectAtIndex:i], [keyList_p objectAtIndex:i]];
}
}
}
NSData * postData = [sPost dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString * postLength = [NSString stringWithFormat:#"%d",[postData length]];
NSURL * url = [NSURL URLWithString:sURL_p];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:5];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
if (theConnection)
{
self.responseData = [NSMutableData data];
}
}
#end
Then you to make this web call, you call it like this
WebCall *webCall = [[WebCall alloc] init];
[webCall setWebCallDidFinish:^(NSString *response){
//This method is called as as soon as the web call is finished
NSString *trimmedString = [response stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([trimmedString rangeOfString:#"failure"].location == NSNotFound)
{
//Successful web call
}
else
{
//If the webcall failed due to an error
}
}];
//Make web call here
[webCall webServiceCall:#"http://www.bbc.co.uk/" :nil :nil];
See the setWebCallDidFinish method, it will not be called until the webcall has finished.
Hope that helps!!
Here is some code which I am using in my app:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:yourURL]];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
NSLog(#"Error loading data from %#. Error Userinfo: %#",yourURL, [error userInfo]);
} else {
NSDictionary *dataFromServer = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
contentAsString = [[[dataFromServer objectForKey:#"page"] objectForKey:#"content"] stripHtml];
completionHandler(contentAsString);
}];
fyi: stripHTML is a NSString Category to remove HTML tags from JSON --> Found it Here
you can call your content in your class like that:
[yourClass getDataWithcompletionHandler:^(NSString *content) {
yourObject.content = content;
[yourClass saveManagedObjectContext];
}];
if you implement it once, you won't want to use synchronous connection again...
Check this out: HTTPCachedController
It will help you send POST and GET requests, while it will cache the response and after that it will return the cached data when no internet connection is available.
HTTPCachedController *ctrl = [[[HTTPCachedController alloc] initWithRequestType:1 andDelegate:self] autorelease];
[ctrl getRequestToURL:#"https://api.github.com/orgs/twitter/repos?page=1&per_page=10"];
You will get notified when the data are fetched through a delegate method:
-(void)connectionFinishedWithData:(NSString*)data andRequestType:(int)reqType

NSURLConnection delegates not being called even when run on main thread

I know that this kind of question has been asked many times, but all of them point to saying that the connection must be on a different thread.
-(void)distanceMatrix{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:distanceMatrixURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10];
connection2 = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[connection2 scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
NSLog(#"Is%# main thread", ([NSThread isMainThread] ? #"" : #" NOT"));
[connection2 start];
if (connection2)
{
responseData2 = [NSMutableData data];
connectionIsActive = YES;
} else {
NSLog(#"connection failed");
}
}
- (void)connection2:(NSURLConnection *)connection2 didReceiveResponse:(NSURLResponse *)response
{NSLog(#"recieved response");
[responseData2 setLength:0];
}
- (void)connection2:(NSURLConnection *)connection2 didReceiveData:(NSData *)data
{
[responseData2 appendData:data];
}
- (void)connection2:(NSURLConnection *)connection2 didFailWithError:(NSError *)error
{
connectionIsActive = NO;
NSLog(#"failed!!");
}
- (void)connection2DidFinishLoading:(NSURLConnection *)conn
{
connectionIsActive = NO;
SBJsonParser *json = [[SBJsonParser alloc] init];
NSString *responseString = [[NSString alloc] initWithData:responseData2 encoding:NSUTF8StringEncoding];
NSError *jsonError = nil;
NSDictionary *parsedJSON = [json objectWithString:responseString error:&jsonError];
travelTime= [[[[parsedJSON valueForKey:#"rows"] valueForKey:#"elements"] valueForKey:#"duration"] valueForKey:#"text"];
NSLog(#"traveltime = %#", travelTime);
}
When I log it, it says that it runs on the main thread. Connection2 is active but none of the delegates are called.
Also, this is the way I am calling distanceMatrix method
-(id)initWithJsonResultDict:(NSDictionary *)jsonResultDict andUserCoordinates: (CLLocationCoordinate2D)userCoords andTimeURL:(NSString*)timeURL
{
self.distanceMatrixURL = timeURL;
[self distanceMatrix];
//more code here for other purposes
}
Because you have added a 2 into the names of all of the delegate methods. That changes the method signature so you aren't implementing the correct methods. Remove all of the 2 at the start of the methods - (void)connection2: and it should work.

How to modify the cookies of a request during redirect in objective-c?

I'm doing a simple login and noticed that during the redirect I only have 2 of the 3 required cookies to get in correctly. I captured the other cookie and put them together but for some reason I can't modify the headers on the fly?
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
NSURL* redirected_url = [request URL];
NSString* querystr = [redirected_url absoluteString];
if (response != nil) {
NSArray* zzzz = [NSHTTPCookie
cookiesWithResponseHeaderFields:[response allHeaderFields]
forURL:[NSURL URLWithString:#""]];
if ([zzzz count] > 0) {
if ([querystr isEqualToString:#"https://www.localhost.com/specificurl.aspx"]) {
NSMutableArray* actualCookies = [[NSMutableArray alloc] init];
NSHTTPCookie* obj = [self.tmpCookies objectAtIndex:0];
[actualCookies addObject:obj];
[actualCookies addObject:zzzz];
NSArray* authToken = [[NSArray alloc] initWithArray:actualCookies];
//BLOWS UP HERE ?? NSDictionary* headers = [NSHTTPCookie requestHeaderFieldsWithCookies:authToken];
//[request setAllHTTPHeaderFields:authToken];
[viewController setAuthCookieAfterValidLogin:zzzz];
}
}
}
return request;
}
The general idea is to set this header to have the value of my combined cookies
I found that although I couldn't modify the existing request, that didn't stop me from creating a new request and simply returning that one :)
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
NSURL* redirected_url = [request URL];
NSString* querystr = [redirected_url absoluteString];
if (response != nil) {
NSArray* zzzz = [NSHTTPCookie
cookiesWithResponseHeaderFields:[response allHeaderFields]
forURL:[NSURL URLWithString:#""]];
if ([zzzz count] > 0) {
if ([querystr isEqualToString:#"https://www.localhost.com/specificurl.aspx"]) {
NSMutableArray* actualCookies = [[NSMutableArray alloc] init];
NSUInteger i, count = [zzzz count];
for (i = 0; i < count; i++) {
NSHTTPCookie* xxx = [zzzz objectAtIndex:i];
[actualCookies addObject:xxx];
}
NSHTTPCookie* obj = [self.tmpCookies objectAtIndex:0];
[actualCookies addObject:obj];
NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies:actualCookies];
NSURL *url = [NSURL URLWithString:#"https://www.localhost.com/specificurl.aspx"];
NSMutableURLRequest* xrequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[xrequest setHTTPMethod:#"GET"];
[xrequest setAllHTTPHeaderFields:headers];
[xrequest setValue:#"https://www.localhost.com/Default.aspx?Site_ID=500000" forHTTPHeaderField: #"Referer"];
[viewController setAuthCookieAfterValidLogin:zzzz];
return xrequest;
}
}
}
return request;
}