-1
我嘗試通過node.js的SOAP調用和我提示以下錯誤:
ReferenceError: $http is not defined
這裏是我的代碼,一切似乎工作,直到它在失敗最後一行:
//Import the `assert` module to validate results.
var assert = require('assert');
var SoapRequestXML='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_5="https://clients.mindbodyonline.com/api/0_5">\r\n' +
'<soapenv:Header/>\r\n' +
'<soapenv:Body>\r\n' +
'<_5:GetClasses>\r\n' +
'<_5:Request>\r\n' +
'<_5:SourceCredentials>\r\n' +
'<_5:SourceName>SOURCECREDENTIALS</_5:SourceName>\r\n' +
'<_5:Password>PASSWORD</_5:Password>\r\n' +
'<_5:SiteIDs>\r\n' +
'<_5:int>-99</_5:int>\r\n' +
'</_5:SiteIDs>\r\n' +
'</_5:SourceCredentials>\r\n' +
'</_5:Request>\r\n' +
'</_5:GetClasses>\r\n' +
'</soapenv:Body>\r\n' +
'</soap:Envelope>';
var options = {
//Define endpoint URL.
url: "https://api.mindbodyonline.com/0_5/ClassService.asmx",
//Define body of POST request.
body: SoapRequestXML,
//Define insert key and expected data type.
headers: {
'POST': 'https://api.mindbodyonline.com/0_5/ClassService.asmx?wsdl HTTP/1.1',
'Accept-Encoding': 'gzip,deflate',
'Content-Type': 'text/xml;charset=UTF-8',
'SOAPAction': '"http://clients.mindbodyonline.com/api/0_5/GetClasses"',
'Content-Length': '594',
'Host': 'api.mindbodyonline.com',
'Connection': 'Keep-Alive',
'User-Agent': 'Apache-HttpClient/4.1.1 (java 1.5)'
}
};
//Define expected results using callback function.
function callback(error, response, body) {
//Log status code to Synthetics console.
console.log(response);
//Verify endpoint returns 200 (OK) response code.
assert.ok(response.statusCode == 200, 'Expected 200 OK response');
//Parse JSON received from Insights into variable.
//
var parseString = require('xml2js').parseString;
var XMLReSULT = response.body;
parseString(XMLReSULT, function (err, result) {
console.dir(result);
});
//Log end of script.
console.log("End reached");
}
//Make GET request, passing in options and callback.
$http.post(options, callback);
任何幫助表示讚賞,我對此很感興趣。
在使用''http $ require = require('http')'之前是否導入了'http'模塊? –
沒有顯示可以表明爲什麼應該定義 – charlietfl
@ Sushanth--將該評論提升爲答案。 OP顯然包含了他的代碼的每一行,包括其他「require」,而其中不包含必要的代碼。 – Malvolio