Web Services 如何在Google应用程序脚本上调用Web服务

oxcyiej7  于 2023-08-06  发布在  Go
关注(0)|答案(1)|浏览(184)

我在SAP中创建了一个Web服务,并尝试从Google应用程序脚本调用此SOAP Web服务。
这个WS是在BASIC身份验证中,在变量响应中,我接收到与我传入的输入相同的wsdl。
我在后端系统调用中遇到了问题
收到不支持的内容类型:”
有人能帮我吗

var user = 'user';
var pwd = 'pwd';
var webservice = 'http://xx.xxx.xx.xx:xxxx/sap/bc/srt/wsdl/flv_10002A111AD1/bndg_url/sap/bc/srt/rfc/sap/zdemo_google_ws/100/zdemo_google_ws/zdemo_google_ws?sap-client=100.wsdl';
function readData() {  

//Clean up anything currently on the spreadsheet  
SpreadsheetApp.getActiveSheet().clear();  

try {  

//Various XML parsing.  
var xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:soap:functions:mc-style\">"
+"<soapenv:Header/>"
+"   <soapenv:Body>"
+"     <urn:ZDemoGoogle>"
+"         <ItWebs>"
+"            <item>"
+"               <Protocol></Protocol>"
+"               <Tasktype></Tasktype>"
+"               <EntryId></EntryId>"
+"               <Account></Account>"
+"               <Mandt></Mandt>"
+"               <Host></Host>"
+"               <Port></Port>"
+"               <Destination></Destination>"
+"               <Path></Path>"
+"               <Counter></Counter>"
+"               <Calltime></Calltime>"
+"               <ExecutionTi></ExecutionTi>"
+"               <DataSend></DataSend>"
+"               <DataSendTi></DataSendTi>"
+"               <DataReceive></DataReceive>"
+"               <DataReceiveTi></DataReceiveTi>"
+"            </item>"
+"         </ItWebs>"
+"      </urn:ZDemoGoogle>"
+"   </soapenv:Body>"
+"</soapenv:Envelope>"

var options = {  
  headers: {  
    "Authorization": "Basic " + Utilities.base64Encode(user + ':' + pwd),
    "method" : "post",
    "contentType" : "text/xml",
    "payload" : xml,
    "muteHttpExceptions":true
  },  
};  

//UrlFetchApp is a powerful built-in library from Google  

var serviceaddress =  webservice ;
var response = UrlFetchApp.fetch(serviceaddress, options);

字符串

mfpqipee

mfpqipee1#

要使用UrlFetchApp.fetch(),需要修改脚本的option。那么这个修改怎么样?

发件人:

var options = {  
  headers: {  
    "Authorization": "Basic " + Utilities.base64Encode(user + ':' + pwd),
    "method" : "post",
    "contentType" : "text/xml",
    "payload" : xml,
    "muteHttpExceptions":true
  },  
};

字符串

收件人:

var options = {  
  headers: {"Authorization": "Basic " + Utilities.base64Encode(user + ':' + pwd)},
  method: "post",
  contentType: "text/xml",
  payload: xml,
  muteHttpExceptions: true,
};

参考:

  • URL获取应用程序.fetch()

如果这不是你问题的直接解决方案,我很抱歉。

相关问题