Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Yet Another SOAP MTOM POST ExampleDemonstrates how to sending a SOAP request with an MTOM/XOP attachment...
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkXml.pb" IncludeFile "CkHttpRequest.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; First build the following XML: ; <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ; xmlns:imp="http://www.yourdomain.it/ImportMultiploWorkflowPAWS/"> ; <soapenv:Header/> ; <soapenv:Body> ; <imp:InputImportMultiploWorkflowPA> ; <usernameEis>MyUsername</usernameEis> ; <passwordEis>MyPassword</passwordEis> ; <postazioneEis>COSO00</postazioneEis> ; <istitutoEis>COSO</istitutoEis> ; <codiceAzienda>COSO0000</codiceAzienda> ; <fileZip><inc:Include href="cid:780931946797" xmlns:inc="http://www.w3.org/2004/08/xop/include"/></fileZip> ; <fileZipName>IT04769180151_00044.zip</fileZipName> ; <workflow>carica</workflow> ; </imp:InputImportMultiploWorkflowPA> ; </soapenv:Body> ; </soapenv:Envelope> xml.i = CkXml::ckCreate() If xml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::setCkTag(xml, "soapenv:Envelope") CkXml::ckAddAttribute(xml,"xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/") CkXml::ckAddAttribute(xml,"xmlns:imp","http://www.yourdomain.it/ImportMultiploWorkflowPAWS/") CkXml::ckUpdateChildContent(xml,"soapenv:Header","") CkXml::ckUpdateChildContent(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|usernameEis","MyUsername") CkXml::ckUpdateChildContent(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|passwordEis","MyPassword") CkXml::ckUpdateChildContent(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|postazioneEis","COSO00") CkXml::ckUpdateChildContent(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|istitutoEis","COSO") CkXml::ckUpdateChildContent(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|codiceAzienda","COSO0000") CkXml::ckUpdateAttrAt(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include",1,"href","cid:780931946797") CkXml::ckUpdateAttrAt(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZip|inc:Include",1,"xmlns:inc","http://www.w3.org/2004/08/xop/include") CkXml::ckUpdateChildContent(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|fileZipName","IT04769180151_00044.zip") CkXml::ckUpdateChildContent(xml,"soapenv:Body|imp:InputImportMultiploWorkflowPA|workflow","carica") ; We want our top-level HTTP request header to look like this: ; POST /http-router-softwarehubsystem/webservices/importMultiploWorkflowPA HTTP/1.1 ; Accept-Encoding: gzip,deflate ; Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="----=_Part_0_1353857996.1546013984933" ; SOAPAction: "http://www.yourdomain.it/ImportMultiploWorkflowPAWS/importMultiploWorkflowPA" ; MIME-Version: 1.0 ; Content-Length: <chilkat will add this header> ; Host: <chilkat will add this header> ; Connection: Keep-Alive ; User-Agent: Apache-HttpClient/4.1.1 (java 1.5) req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::setCkHttpVerb(req, "POST") CkHttpRequest::setCkPath(req, "/http-router-softwarehubsystem/webservices/importMultiploWorkflowPA") CkHttpRequest::setCkContentType(req, "multipart/related; type=" + Chr(34) + "application/xop+xml" + Chr(34) + "; start=" + Chr(34) + "<rootpart@soapui.org>" + Chr(34) + "; start-info=" + Chr(34) + "text/xml" + Chr(34)) CkHttpRequest::ckAddHeader(req,"SOAPAction",Chr(34) + "http://www.yourdomain.it/ImportMultiploWorkflowPAWS/importMultiploWorkflowPA" + Chr(34)) CkHttpRequest::ckAddHeader(req,"Accept-Encoding","gzip,deflate") CkHttpRequest::ckAddHeader(req,"Mime-Version","1.0") CkHttpRequest::ckAddHeader(req,"Connection","Keep-Alive") CkHttpRequest::ckAddHeader(req,"User-Agent","Apache-HttpClient/4.1.1 (java 1.5)") ; Add the XML content for the 1st MIME sub-part. CkXml::setCkEmitXmlDecl(xml, 0) CkXml::setCkEmitCompact(xml, 0) success = CkHttpRequest::ckAddStringForUpload2(req,"","",CkXml::ckGetXml(xml),"utf-8","application/xop+xml; charset=UTF-8; type=" + Chr(34) + "text/xml" + Chr(34)) ; We want the 1st sub-header (the sub-part containing the XML) to look like this: ; Content-Type: application/xop+xml; charset=UTF-8; type="text/xml" ; Content-Transfer-Encoding: 8bit ; Content-ID: <rootpart@soapui.org> ; Make sure we set sub-headers *after* calling AddStringForUpload2, otherwise AddStringForUpload2 might change these explicitly set headers. success = CkHttpRequest::ckAddSubHeader(req,0,"Content-Transfer-Encoding","8bit") success = CkHttpRequest::ckAddSubHeader(req,0,"Content-ID","<rootpart@soapui.org>") ; Add a reference to the local file for the file data for the 2nd MIME sub-part. success = CkHttpRequest::ckAddFileForUpload2(req,"","qa_data/zips/helloWorld.zip","application/zip; name=IT04769180151_00044.zip") ; We want the 2nd sub-header (for the MIME sub-part containing a .zip file) to look like this: ; Content-Type: application/zip; name=IT04769180151_00044.zip ; Content-Transfer-Encoding: binary ; Content-ID: <IT04769180151_00044.zip> ; Content-Disposition: attachment; name="IT04769180151_00044.zip"; filename="IT04769180151_00044.zip" ; Make sure we set sub-headers *after* calling AddFileForUpload2, otherwise AddFileForUpload2 might change these explicitly set headers. success = CkHttpRequest::ckAddSubHeader(req,1,"Content-Transfer-Encoding","binary") success = CkHttpRequest::ckAddSubHeader(req,1,"Content-ID","<IT04769180151_00044.zip>") success = CkHttpRequest::ckAddSubHeader(req,1,"Content-Disposition","attachment; name=" + Chr(34) + "IT04769180151_00044.zip" + Chr(34) + "; filename=" + Chr(34) + "IT04769180151_00044.zip" + Chr(34)) ; Keep a session log so we can examine the exact request/response. ; Remove this line when finished with debugging. CkHttp::setCkSessionLogFilename(http, "qa_output/mtom_sessionLog.txt") useTls.i = 0 ; Note: Please don't run this example without changing the domain to your own domain... resp.i = CkHttp::ckSynchronousRequest(http,"www.yourdomain.it",80,useTls,req) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkXml::ckDispose(xml) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf xmlResponse.i = CkXml::ckCreate() If xmlResponse.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkXml::ckLoadXml(xmlResponse,CkHttpResponse::ckBodyStr(resp)) ; println xmlResponse.GetXml(); CkHttpResponse::ckDispose(resp) Debug "OK." CkHttp::ckDispose(http) CkXml::ckDispose(xml) CkHttpRequest::ckDispose(req) CkXml::ckDispose(xmlResponse) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.