2017-07-31 140 views
0

我试图调用内部Bluemix另一API或者使用IBM Bluemix(API连接)的内部网关脚本中使用下面的代码的任何其它HTTPS POST方法的HTTPS POST方法:如何调用IBM Bluemix使用gatewayscript APIConnect

var urlopen = require('urlopen'); 
var options = { 
      target: 'https://pokemons.mybluemix.net/api/pokemons/1', 
      method: 'POST', 
      headers: {}, 
      contentType: 'application/json', 
      timeout: 60, 
      data: {"Message": "DataPower GatewayScript"} 

}; 

urlopen.open(options, function(error, response) { 
    if (error) { 
    // an error occurred during the request sending or response header parsing 
    session.output.write("urlopen error: "+JSON.stringify(error)); 
    } else { 
    // get the response status code 
    var responseStatusCode = response.statusCode; 
    var responseReasonPhrase = response.reasonPhrase; 
    console.log("Response status code: " + responseStatusCode); 
    console.log("Response reason phrase: " + responseReasonPhrase); 
    // reading response data 
    response.readAsBuffer(function(error, responseData){ 
     if (error){ 
     throw error ; 
     } else { 
     session.output.write(responseData) ; 
     apim.output('application/json'); 
     } 
    }); 
    } 
}); 

但我收到以下错误:

{ 
    "httpCode": "500", 
    "httpMessage": "Internal Server Error", 
    "moreInformation": "URL open: Cannot create connection to 'https://pokemons.mybluemix.net/api/pokemons/1', status code: 7" 
} 

看起来有一些问题与SSL连接。如果是这样,我如何在IBM Bluemix API Connect中获取默认沙盒目录的SSL详细信息?或者,我如何使HTTPS POST调用上面的示例URL?

回答

0

由于5.0.6版本:

IBM API Connect 5.0.x

Forward SSLProxy (and Crypto) is replaced with SSLClient. These new profiles support ephemeral ciphers (DHE and ECDHE), perfect forward secrecy, and Server Name Indication (SNI) extension. Note that DHE ciphers in DataPower SSLServerProfile use 2048-bit DH parameters (as server) and accept 1024-bit DH parameters (as client).

为了让您具体的例子来对API的连接工作,使用HTTPS你需要指定sslClientProfile。

例如:

var urlopen = require('urlopen'); 
var options = { 
      target: 'https://pokemons.mybluemix.net/api/pokemons/1', 
      method: 'POST', 
      headers: {}, 
      contentType: 'application/json', 
      timeout: 60, 
      sslClientProfile: 'webapi-sslcli-mgmt', 
      data: {"Message": "DataPower GatewayScript"} 

};