Zig
Zig
HTTP SOAP 1.2 Request and Response using POST
See more HTTP Examples
Demonstrates a working SOAP 1.2 request and response using POST with a live server. You may try running this example with the URLs and data provided. See http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP for details.Note: This example is correct in theory, but no longer works for live testing because the SOAP service provider (cdyne.com) has made changes or discontinued the free service.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// --------------------------------------------------------------------------------
// Also see Chilkat's Online WSDL Code Generator
// to generate code and SOAP Request and Response XML for each operation in a WSDL.
// --------------------------------------------------------------------------------
const http = try chilkat.Http.init();
defer http.deinit();
const soap_xml = try chilkat.Xml.init();
defer soap_xml.deinit();
soap_xml.setTag("soap12:Envelope");
try soap_xml.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
try soap_xml.addAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
try soap_xml.addAttribute("xmlns:soap12", "http://www.w3.org/2003/05/soap-envelope");
soap_xml.newChild2("soap12:Body", "");
try soap_xml.getChild2(0);
soap_xml.newChild2("GetCityWeatherByZIP", "");
try soap_xml.getChild2(0);
try soap_xml.addAttribute("xmlns", "http://ws.cdyne.com/WeatherWS/");
soap_xml.newChild2("ZIP", "60187");
soap_xml.getRoot2();
std.debug.print("{s}\n", .{try soap_xml.getXml(alloc)});
const req = try chilkat.HttpRequest.init();
defer req.deinit();
req.setHttpVerb("POST");
req.setSendCharset(false);
req.addHeader("Content-Type", "application/soap+xml; charset=utf-8");
req.addHeader("SOAPAction", "http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP");
req.setPath("/WeatherWS/Weather.asmx");
try req.loadBodyFromString(try soap_xml.getXml(alloc), "utf-8");
http.setFollowRedirects(true);
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpSReq("wsf.cdyne.com", 80, false, req, resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const xml_response = try chilkat.Xml.init();
defer xml_response.deinit();
try xml_response.loadXml(try resp.getBodyStr(alloc));
std.debug.print("{s}\n", .{try xml_response.getXml(alloc)});
}