由于某些原因,当我尝试向Salesforce创建简单的登录请求时遇到此错误。
这与邮递员中的工作完全一样,但是,当我尝试转换为Google Apps脚本时,似乎会出现“文件过早结束”错误。
var myHeaders = {
"Content-Type": 'text/xml',
SOAPAction: '/',
Cookie: "BrowserId=sB-PspOVEeqEttdm-K56tw",
}
/*myHeaders.append("Content-Type", "text/xml");
myHeaders.append("SOAPAction", "\"\"");
myHeaders.append("Cookie", "BrowserId=sB-PspOVEeqEttdm-K56tw");*/
var raw = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <Header>\n </Header>\n <Body>\n <login xmlns=\"urn:enterprise.soap.sforce.com\">\n <username>xx@xx.com</username>\n <password>xx</password>\n </login>\n </Body>\n</Envelope>";
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow',
muteHttpExceptions : true
};
var response = UrlFetchApp.fetch("https://test.salesforce.com/services/Soap/c/48.0/", requestOptions)
//.then(response => response.text())
//.then(result => logger.log(result))
//.catch(error => logger.log('error', error));
Logger.log(response.getContentText())```
答案 0 :(得分:2)
该修改如何?
Cookie: "BrowserId=sB-PspOVEeqEttdm-K56tw"
。body
和redirect
的属性未包含在UrlFetchApp.fetch
的参数中。var myHeaders = {
SOAPAction: '/',
}
var raw = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <Header>\n </Header>\n <Body>\n <login xmlns=\"urn:enterprise.soap.sforce.com\">\n <username>xx@xx.com</username>\n <password>xx</password>\n </login>\n </Body>\n</Envelope>";
var requestOptions = {
method: 'POST',
headers: myHeaders,
contentType: "text/xml",
payload: raw,
muteHttpExceptions : true
};
var response = UrlFetchApp.fetch("https://test.salesforce.com/services/Soap/c/48.0/", requestOptions);
Logger.log(response.getContentText())
SOAPAction
,raw
和https://test.salesforce.com/services/Soap/c/48.0/
的值是正确的。