首页 > 解决方案 > strong-soap:通过 https 调用服务方法

问题描述

我正在尝试使用 strong-soap node.js 库调用 SOAP 服务。尽管我确实将客户端安全设置为 ClientSSLSecurity,但在客户端上调用方法时出现错误:

TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"

如何告诉 stong-soap 使用 https?

到目前为止,这是我的代码:

"use strict";
 
var soap = require('strong-soap').soap;
var constants = require('constants');
var url = 'http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.wsdl';
var WSDL = soap.WSDL;
var options = {};
WSDL.open(url,options,
  function(err, wsdl) {
    if (err) {
      console.log(err);
      return;
    }

    var clientOptions = {
      WSDL_CACHE : {
        caqhcorewsdl: wsdl
      }
    };
    soap.createClient('caqhcorewsdl', clientOptions, function(err, client) {
      if (err) {
        console.log(err);
        return;
      }
      else {
        client.setSecurity(new soap.ClientSSLSecurity(
            'rob.keystore'
          , 'cert.pem'
          , {
            strictSSL: true,
            secureOptions: constants.SSL_OP_NO_TLSv1_2
          }
        ));
        if(err) {
            console.error(err);
            return;
        }
        else {
          console.log('success!');
          client.RealTimeTransaction({name: 'value'}, function(err, result, envelope, soapHeader) {
            if(err) {
              // ERROR IS THROWN HERE:
              console.error(err);
              return;
            }
            else {
              console.log('success!');
            }
          });
        }
      }
    });
});

谢谢!

抢G

标签: sslsoapsoap-clientstrong-soap

解决方案


用这一行替换以下行:

var url = 'https://www.caqh.org/SOAP/WSDL/CORERule2.2.0.wsdl';

推荐阅读