2017-07-31 227 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"} 

};