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.}