使用SoapUI时,我一直有错误,直到我更正了参数(现在我得到了所需的响应)。
根据API文档:
"Wrap the following XML structure in a variable called 'callmeasurement_xml_input' "
<?xml version="1.0" encoding="UTF-8"?>
<callmeasurement username="abc" password="123" api="1"/>SoapUI中的功能“参数”是:
?callmeasurement_xml_input=<?xml version="1.0" encoding="utf-16"?><callmeasurement username="abc" password="123" api="1111"/>这是我当前的(不工作的) AppsScript:
function apiRequest(){
var url = 'http://api.callmeasurement.com/api/dnis_list.cfm';
var rawXML = '<callmeasurement_xml_input>'
+ '<?xml version="1.0" encoding="utf-16"?>'
+ '<callmeasurement username="abc" password="123" api="1111"/>'
+ '</callmeasurement_xml_input>';
var options = {
'contentType': 'application/xml',
'method': 'POST',
'payload': rawXML
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
// Returns an error
}发布于 2020-04-27 04:11:00
应该对XML进行编码并在callmeasurement_xml_input查询参数中传递,而不是将其包装在callmeasurement_xml_input元素中,然后将其发布到有效负载中。
function apiRequest(){
var rawXML = '<?xml version="1.0" encoding="utf-16"?>'
+ '<callmeasurement username="abc" password="123" api="1111"/>';
var url = 'http://api.callmeasurement.com/api/dnis_list.cfm'
+ '?callmeasurement_xml_input=' + encodeURIComponent(rawXML);
var options = {'method': 'POST'};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}https://stackoverflow.com/questions/52858386
复制相似问题