Google Apps SOAP请求似乎发送GET请求而不是POST

时间:2020-01-23 20:19:27

标签: google-apps-script

我正在尝试发送一个简单的SOAP请求,该请求我知道可以通过SOAPUI进行测试,但是似乎下面的Google Apps Script忽略了POST并以get方式发送,因为响应是通过WSDL的GET返回的页面。

var webservice = 'https://ws.campaigner.com/2013/01/contactmanagement.asmx?WSDL';
//Various XML parsing.  
var xml = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="https://ws.campaigner.com/2013/01">'
+'   <soap:Header/>'
+'   <soap:Body>'
+'      <ns:ImmediateUpload>'
+'         <!--Optional:-->'
+'        <ns:authentication>'
+'            <!--Optional:-->'
+'            <ns:Username>user</ns:Username>'
+'            <!--Optional:-->'
+'            <ns:Password>pass</ns:Password>'
+'         </ns:authentication>'
+'         <ns:UpdateExistingContacts>true</ns:UpdateExistingContacts>'
+'         <ns:TriggerWorkflow>false</ns:TriggerWorkflow>'
+'         <!--Optional:-->'
+'         <ns:contacts>'
+'            <!--Zero or more repetitions:-->'
+'            <ns:ContactData>'
+'               <!--Optional:-->'
+'               <ns:ContactKey>'
+'                  <!--<ns:ContactId>?</ns:ContactId>-->'
+'                  <!--Optional:-->'
+'                  <ns:ContactUniquedentifier>email</ns:ContactUniqueIdentifier>'
+'               </ns:ContactKey>'
+'               <!--Optional:-->'
+'               <ns:EmailAddress IsNull="false">email</ns:EmailAddress>'
+'               <!--Optional:-->'
+'               <ns:FirstName IsNull="true"></ns:FirstName>'
+'               <!--Optional:-->'
+'               <ns:LastName IsNull="true"></ns:LastName>'
+'               <!--Optional:-->'
+'               <ns:PhoneNumber IsNull="true"></ns:PhoneNumber>'
+'               <!--Optional:-->'
+'               <ns:Fax IsNull="true"></ns:Fax>'
+'               <ns:Status>Subscribed</ns:Status>'
+'               <ns:MailFormat>Both</ns:MailFormat>'
+'               <ns:IsTestContact>false</ns:IsTestContact>'
+'               <!--Optional:-->'
+'               <ns:CustomAttributes>'
+'                  <!--Zero or more repetitions:-->'
+'                  <ns:CustomAttribute Id="9553008" IsNull="false">08/19/2020 4:00 PM</ns:CustomAttribute>'
+'               </ns:CustomAttributes>'
+'               <!--Optional:-->'
+'               <ns:AddToGroup>'
+'                  <!--Zero or more repetitions:-->'
+'                  <!--<ns:int>?</ns:int>-->'
+'               </ns:AddToGroup>'
+'               <!--Optional:-->'
+'               <ns:RemoveFromGroup>'
+'                  <!--Zero or more repetitions:-->'
+'                  <!--<ns:int>?</ns:int>-->'
+'               </ns:RemoveFromGroup>'
+'            </ns:ContactData>'
+'         </ns:contacts>'
+'         <!--Optional:-->'
+'         <ns:globalAddToGroup>'
+'            <!--Zero or more repetitions:-->'
+'            <!--<ns:int>?</ns:int>-->'
+'         </ns:globalAddToGroup>'
+'         <!--Optional:-->'
+'         <ns:globalRemoveFromGroup>'
+'            <!--Zero or more repetitions:-->'
+'            <!--<ns:int>?</ns:int>-->'
+'         </ns:globalRemoveFromGroup>'
+'      </ns:ImmediateUpload>'
+'   </soap:Body>'
+'</soap:Envelope>';

var options = {   
  headers:{
       method : 'post',
       payload  : xml,
       contentType : 'text/xml; charset=utf-8',
      'SOAPAction' : '"https://ws.campaigner.com/2013/01/ImmediateUpload"',
       muteHttpExceptions : true
  },

};  


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

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

我不熟悉Google Apps脚本。

1 个答案:

答案 0 :(得分:3)

您的选项对象格式不正确。它应显示为:

var options = {
    method:"POST",
    contentType: "text/xml; charset=utf-8",
    muteHttpExceptions:true,
    headers:{
        "SOAPAction": "https://ws.campaigner.com/2013/01/ImmediateUpload"
    },
    payload:xml
};