1
我正在尝试对需要相互认证的服务器进行API调用。 使用和的NodeJS请求库我可以用下面的代码什么是iOS中相互验证的等效代码?
var keyFile = '/Users/username/Documents/Certificates/example-key.pem';
var certificateFile = '/Users/username/Documents/Certificates/cert.pem';
var options = {
uri: 'https://myserver.com/apiOne',
key: fs.readFileSync(keyFile),
cert: fs.readFileSync(certificateFile),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Basic ' + new Buffer(userId + ':' + password).toString('base64')
},
body: data //JSON body
};
request.postAsync(options)
.spread(function (response, body) {
res.status(200).json(JSON.parse(body));
})
.catch(function (err) {
res.status(400).send(err);
})
我如何从iOS应用程序打相同的API打API? 我使用下面的代码,但没有从服务器
func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) {
if challenge.protectionSpace.authenticationMethod == "NSURLAuthenticationMethodServerTrust" {
let credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust)
什么密钥和证书指的是在代码的NodeJS响应?我如何在iOS中传递它们?
我没有使用此推送通知。我只是想做一个需要相互认证的API调用。 – vivek241