Javascript 如何在Postman工具的请求前脚本中提供soap xml正文
我试图在Postman预请求脚本中添加一个脚本,该脚本将返回一个令牌。以下是请求的伪代码。我无法在请求主体中设置soap xml。这需要帮助 邮递员预请求脚本: 下面提到的是在上述请求中设置为正文的XML: 下面是我试过的 请求: 答复:Javascript 如何在Postman工具的请求前脚本中提供soap xml正文,javascript,soap,salesforce,postman,Javascript,Soap,Salesforce,Postman,我试图在Postman预请求脚本中添加一个脚本,该脚本将返回一个令牌。以下是请求的伪代码。我无法在请求主体中设置soap xml。这需要帮助 邮递员预请求脚本: 下面提到的是在上述请求中设置为正文的XML: 下面是我试过的 请求: 答复: 你应该给我们更多的信息,一些你失败的尝试,等等。 希望这会有帮助: pm.sendRequest({ url: "https://test.salesforce.com/services/Soap/c/42.0", method: "POST"
你应该给我们更多的信息,一些你失败的尝试,等等。 希望这会有帮助:
pm.sendRequest({
url: "https://test.salesforce.com/services/Soap/c/42.0",
method: "POST",
header: {
'Content-Type': 'text/xml',
'SOAPAction': ''
},
body: {
mode:"raw",
raw: `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="urn:enterprise.soap.sforce.com">
<SOAP-ENV:Header>
<ns2:Header>
</ns2:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns3:login xmlns:ns3="urn:enterprise.soap.sforce.com" xmlns="">
<ns3:username>USERNAME</ns3:username>
<ns3:password>PASSWORD</ns3:password>
</ns3:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
}
},
function (err, res) {
console.log("Response - " + res);
}
);
请注意,这用于逐字表示原始字符串。您应该向我们提供更多信息,以及您的一些失败尝试,等等。 希望这会有帮助:
pm.sendRequest({
url: "https://test.salesforce.com/services/Soap/c/42.0",
method: "POST",
header: {
'Content-Type': 'text/xml',
'SOAPAction': ''
},
body: {
mode:"raw",
raw: `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="urn:enterprise.soap.sforce.com">
<SOAP-ENV:Header>
<ns2:Header>
</ns2:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns3:login xmlns:ns3="urn:enterprise.soap.sforce.com" xmlns="">
<ns3:username>USERNAME</ns3:username>
<ns3:password>PASSWORD</ns3:password>
</ns3:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
}
},
function (err, res) {
console.log("Response - " + res);
}
);
请注意,它用于逐字表示原始字符串。因此,最后,在@Borys Fursov的帮助下,我找到了问题的解决方案。 以下是正确的请求-
pm.sendRequest({
url: "https://test.salesforce.com/services/Soap/c/42.0",
method: "POST",
header: {
'Content-Type': 'text/xml',
'SOAPAction': '""'
},
body: {
mode:"raw",
raw: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns2=\"urn:enterprise.soap.sforce.com\"><SOAP-ENV:Header><ns2:Header></ns2:Header></SOAP-ENV:Header><SOAP-ENV:Body><ns3:login xmlns:ns3=\"urn:enterprise.soap.sforce.com\" xmlns=\"\"><ns3:username>xxxxxxxxxx@xxxxx.com</ns3:username><ns3:password>xxxxxxxxxxxxxxxxxxxx</ns3:password></ns3:login></SOAP-ENV:Body></SOAP-ENV:Envelope> "
}
},
function (err, res) {
if (res.code === 200) {
// console.log("Response - " + res.text());
var responseJson = xml2Json(res.text());
var sessionId = responseJson['soapenv:Envelope']['soapenv:Body'].loginResponse.result.sessionId;
console.log("Session id - " + sessionId);
pm.globals.set("session_id", sessionId);
} else {
console.log("Response - " + res.code + " " + res.reason());
console.log("Response - " + res.text());
}
}
);
很遗憾,由于敏感信息,我无法粘贴输出。谢谢 最后,在@Borys Fursov的帮助下,我找到了问题的解决方案。 以下是正确的请求-
pm.sendRequest({
url: "https://test.salesforce.com/services/Soap/c/42.0",
method: "POST",
header: {
'Content-Type': 'text/xml',
'SOAPAction': '""'
},
body: {
mode:"raw",
raw: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns2=\"urn:enterprise.soap.sforce.com\"><SOAP-ENV:Header><ns2:Header></ns2:Header></SOAP-ENV:Header><SOAP-ENV:Body><ns3:login xmlns:ns3=\"urn:enterprise.soap.sforce.com\" xmlns=\"\"><ns3:username>xxxxxxxxxx@xxxxx.com</ns3:username><ns3:password>xxxxxxxxxxxxxxxxxxxx</ns3:password></ns3:login></SOAP-ENV:Body></SOAP-ENV:Envelope> "
}
},
function (err, res) {
if (res.code === 200) {
// console.log("Response - " + res.text());
var responseJson = xml2Json(res.text());
var sessionId = responseJson['soapenv:Envelope']['soapenv:Body'].loginResponse.result.sessionId;
console.log("Session id - " + sessionId);
pm.globals.set("session_id", sessionId);
} else {
console.log("Response - " + res.code + " " + res.reason());
console.log("Response - " + res.text());
}
}
);
很遗憾,由于敏感信息,我无法粘贴输出。谢谢 为什么不使用postman的body部分?@Sathish这是一个预请求脚本,将在body部分已经提到的主体请求之前执行。预请求脚本允许您为该特定请求生成先决条件。在这种情况下,它将帮助我获得所需的身份验证令牌。为什么不使用postman的body部分?@Sathish这是一个预请求脚本,将在body部分中已经提到的主体的主请求之前执行。预请求脚本允许您为该特定请求生成先决条件。在这种情况下,它将帮助我获得所需的身份验证令牌。谢谢!现在,根据你的建议,我发现缺少标题异常。谢谢!现在,根据你的建议,我得到了缺少标题异常。
pm.sendRequest({
url: "https://test.salesforce.com/services/Soap/c/42.0",
method: "POST",
header: {
'Content-Type': 'text/xml',
'SOAPAction': ''
},
body: {
mode:"raw",
raw: `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="urn:enterprise.soap.sforce.com">
<SOAP-ENV:Header>
<ns2:Header>
</ns2:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns3:login xmlns:ns3="urn:enterprise.soap.sforce.com" xmlns="">
<ns3:username>USERNAME</ns3:username>
<ns3:password>PASSWORD</ns3:password>
</ns3:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
}
},
function (err, res) {
console.log("Response - " + res);
}
);
pm.sendRequest({
url: "https://test.salesforce.com/services/Soap/c/42.0",
method: "POST",
header: {
'Content-Type': 'text/xml',
'SOAPAction': '""'
},
body: {
mode:"raw",
raw: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns2=\"urn:enterprise.soap.sforce.com\"><SOAP-ENV:Header><ns2:Header></ns2:Header></SOAP-ENV:Header><SOAP-ENV:Body><ns3:login xmlns:ns3=\"urn:enterprise.soap.sforce.com\" xmlns=\"\"><ns3:username>xxxxxxxxxx@xxxxx.com</ns3:username><ns3:password>xxxxxxxxxxxxxxxxxxxx</ns3:password></ns3:login></SOAP-ENV:Body></SOAP-ENV:Envelope> "
}
},
function (err, res) {
if (res.code === 200) {
// console.log("Response - " + res.text());
var responseJson = xml2Json(res.text());
var sessionId = responseJson['soapenv:Envelope']['soapenv:Body'].loginResponse.result.sessionId;
console.log("Session id - " + sessionId);
pm.globals.set("session_id", sessionId);
} else {
console.log("Response - " + res.code + " " + res.reason());
console.log("Response - " + res.text());
}
}
);