Error -1005 Lost connection

I posted this this morning but got the message that a moderator has to approve it and, I think, that was due to a URL being in it(part of the error message), so I have reviewed it. Hopefully, this one gets through.


I am attempting to retrieve a session ID for the eBay trading API for a Mac OSX app. I have successfully connected and retrieved the categories and subcategories; however, the next task is to get a session ID and, eventually, an auth token. The initial call is to GetSessionID, which seems to execute OK and results in a delegate call to didReceiveChallenge. After supplying the credentials using the completion handler provided by the challenge, my completion handler for the intial call is called and results in an error -1005, which is connection was lost.


At this point, I am using the eBay sandbox, not the production server; however, I just tried the production server, same issue.


Here is the code:


-(void) retrieveSessionID{

NSURLSessionConfiguration* configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];


NSMutableString* urlString = [[NSMutableString alloc]initWithCapacity:200];

[urlString appendString:sandBoxEndPoint];


NSString* callname = @"GetSessionID";

NSString* version = @"787";

NSString* contentType = @"text/xml";

NSString* siteID = @"0";


NSMutableDictionary* headersDictionary = [[NSMutableDictionary alloc]initWithCapacity:10];


[headersDictionary setObject:contentType forKey:@"Content-Type"];

[headersDictionary setObject:sandBoxAppID forKey:@"X-EBAY-API-APP-NAME"];

[headersDictionary setObject:devID forKey:@"X-EBAY-API-DEV-NAME"];

[headersDictionary setObject:sandBoxCertID forKey:@"X-EBAY-API-CERT-NAME"];

[headersDictionary setObject:callname forKey:@"X-EBAY-API-CALL-NAME"];

[headersDictionary setObject:version forKey:@"X-EBAY-API-COMPATIBILITY-LEVEL"];

[headersDictionary setObject:siteID forKey:@"X-EBAY-API-SITEID"];


configuration.HTTPAdditionalHeaders = headersDictionary;


NSLog(@"configuration.HTTPAdditionalHeaders: %@", configuration.HTTPAdditionalHeaders);


NSLog(@"urlString: %@", urlString);


NSURL *eBayUrl = [NSURL URLWithString:urlString];


NSLog(@"eBayUrl: %@", eBayUrl);


NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:eBayUrl];

request.HTTPMethod = @"GET";


NSXMLElement *root = [[NSXMLElement alloc] initWithName:@"GetSessionIDRequest"];

[root addAttribute:[NSXMLNode attributeWithName:@"xmnls" stringValue:@"urn:ebay:apis:eBLBaseComponents"]];

NSXMLElement *childElement1 = [[NSXMLElement alloc] initWithName:@"RuName"];

childElement1.stringValue = sandBoxRuName;

[root addChild:childElement1];

NSXMLDocument *xmlRequest = [NSXMLDocument documentWithRootElement:root];


NSData* xmlRequestAsData = [xmlRequest XMLData];


request.HTTPBody = xmlRequestAsData;

NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request

completionHandler:^(NSData *data,

NSURLResponse *response,

NSError *error) {

NSLog(@"error: %@", error);

NSLog(@"response: %@", response);

self.sessionIDRequestXMLstring = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSLog(@"self.sessionIDRequestXMLstring: %@", self.sessionIDRequestXMLstring);

[self.delegate receivedSessionIDRequestXMLstring:self.sessionIDRequestXMLstring];

}

];


[dataTask resume];

}



- (void)URLSession:(NSURLSession *)session

didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge

completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition,

NSURLCredential *credential))completionHandler{

NSLog(@"didReceiveChallenge: %@", challenge);

NSLog(@"session: %@", session);


NSURLCredential* credential = [NSURLCredential credentialWithUser:sandBoxUserID password:sandBoxPassword persistence:NSURLCredentialPersistenceForSession];


completionHandler(NSURLSessionAuthChallengeUseCredential, credential);

}


Here is the error:

error: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x608000055810 {Error .........._kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.}

This error,

NSURLErrorDomain
/
NSURLErrorNetworkConnectionLost
(-1005), means that the server unexpectedly dropped the connection while OS X was waiting for a response. Assuming the network is working, it’s likely that this is the result of logic running on the server. There are lots of potential reasons for that, and only folks with insight into the server can tell you exactly what’s going on. Common causes are:
  • bugs in the server

  • a malformed request

  • authentication problems

With regards authentication, you seem to be responding to all authentication callenges with a user name and password credential. That’s not correct. You should filter on the challenge type (

challeng.protectionSpace.authenticationMethod
) and respond to each challenge appropriately. For example, in most cases you want to respond to
NSURLAuthenticationMethodServerTrust
with
NSURLSessionAuthChallengePerformDefaultHandling
.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Error -1005 Lost connection
 
 
Q