Hi Hermanni,
Sorry, I was pulled away for work with higher priority.
Today I tried your code and I still got "The header is empty when connecting to URL " error for url-open call. Can you have a look at it?
- I created a DataPower gateway between my postman client and FileCloud. The flow is postman ---https--->DataPower gateway---https-->FileCloud. I used postman to test and it works.
- But when I added a gatewayscript action to call FileCloud using url-open in the above DataPower gateway. I used same postman to test. I see url-open failed with error "The header is empty when connecting to URL "
I don't know how to attach DataPower gateway, package capture, and error report here. If you let me know your email, I shall send them to you. but my gateway script is like below
var urlopen = require ('urlopen');
var options = {
target: 'https://doisftp.filecloudonline.com:443/core/loginguest',
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0',
Accept: 'text/plain',
'Accept-Charset': 'utf-8',
'Accept-Encoding': 'gzip,deflate,br',
'Connection': 'keep-alive',
'Cookie': 'tonido-login-user=victor.reyesviloria; X-XSRF-TOKEN=t1ds0lqchfmtjwhq1jhe; tonido-login-seed=d97b61b2-ec18-4f97-8fee-0b6afd52d350; tonido-login-hash=5d01574b4e09500969013196ed1029bfde4158c6; X-XSRF-TOKEN-user=sswoeg10prs0bwxdnnur'
},
data: "password=pwd123&userid=victor.smith"
};
// open connection to target and send data over
urlopen.open(options, function (error, response) {
console.error("start calling url-open");
if (error) {
console.error("start calling url-open failed.");
// an error occurred during request sending or response header parsing
session.output.write ("urlopen connect error: " + JSON.stringify(error));
} else {
// read response data
// get the response status code
var responseStatusCode = response.statusCode;
console.error("responseStatusCode=" + responseStatusCode);
if (responseStatusCode == 200) {
response.readAsBuffer(function(error, responseData) {
if (error) {
// error while reading response or transferring data to Buffer
session.output.write("readAsBuffer error: " + JSON.stringify(error));
} else {
console.error("responseData=" + responseData);
session.output.write(responseData);
}
});
} else {
session.output.write ("urlopen target return statusCode " + responseStatusCode);
}
}
}); // end of urlopen.open()
////////////////////////////////////////////
Note:
- as the userid and pwd are client, I changed to a fake one
- Some headers are from Postman node.js code for good testing the gateway with url-open call added.
Thanks,
Tang
#DataPower#Support#SupportMigration