Skip to content

Instantly share code, notes, and snippets.

@minostro
Created March 22, 2015 20:32
Show Gist options
  • Save minostro/fd138eec3c356cfdcb7e to your computer and use it in GitHub Desktop.
Save minostro/fd138eec3c356cfdcb7e to your computer and use it in GitHub Desktop.
SOAP with Erlang
application:start(inets).
SoapBody = "<soap:Body><GetWeather xmlns=\"http://www.webserviceX.NET\"><CityName>Chicago</CityName><CountryName>United States</CountryName></GetWeather></soap:Body>".
SoapEnvelope = lists:append([
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">",
SoapBody,
"</soap:Envelope>"]
).
{ok, {{_, _, _}, _, ResponseBody}} = httpc:request(post, {"http://www.webservicex.net/globalweather.asmx", [], "text/xml", SoapEnvelope}, [], []).
{Xml, _} = xmerl_scan:string(ResponseBody).
{_, _, [{_, _, [{_, _, [{_, [], Data}]}]}]} = xmerl_lib:simplify_element(Xml).
{XmlData, _} = xmerl_scan:string(lists:append(Data), [{encoding, latin1}]).
xmerl_lib:simplify_element(XmlData).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment