SOAP: Difference between revisions
Content added Content deleted
m (→{{header|Go}}: Corrected capitalization of SOAP in preamble.) |
|||
Line 355: | Line 355: | ||
<pre>{CelsiusToFahrenheitResult => [212]} |
<pre>{CelsiusToFahrenheitResult => [212]} |
||
{FahrenheitToCelsiusResult => [100]} |
{FahrenheitToCelsiusResult => [100]} |
||
</pre> |
|||
=={{header|Phix}}== |
|||
translated from https://gist.github.com/p120ph37/8281362ae9da042f3043 |
|||
<lang Phix>-- demo\rosetta\SOAP.exw |
|||
include builtins\libcurl.e |
|||
include builtins\xml.e -- xml_encode() |
|||
function write_callback(atom pData, integer size, integer nmemb, atom /*pUserdata*/) |
|||
integer bytes_written = size*nmemb |
|||
puts(1,peek({pData,bytes_written})) |
|||
return bytes_written |
|||
end function |
|||
constant write_cb = call_back({'+',routine_id("write_callback")}) |
|||
function compose_soap_frobnicate(string foo, bar, baz) |
|||
return sprintf(""" |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|||
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
|||
<soap:Body> |
|||
<frobnicate xmlns="http://example.com/frobnicate"> |
|||
<foo>%s</foo> |
|||
<bar>%s</bar> |
|||
<baz>%s</baz> |
|||
</frobnicate> |
|||
</soap:Body> |
|||
</soap:Envelope>""",{xml_encode(foo),xml_encode(bar),xml_encode(baz)}) |
|||
end function |
|||
curl_global_init() |
|||
atom curl = curl_easy_init() |
|||
curl_easy_setopt(curl, CURLOPT_URL, "https://ameriwether.com/cgi-bin/info.pl") |
|||
string soap = compose_soap_frobnicate("'Ein'", ">Zwei<", "\"Drei\"") |
|||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, soap) |
|||
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC) |
|||
curl_easy_setopt(curl, CURLOPT_USERNAME, "user") |
|||
curl_easy_setopt(curl, CURLOPT_PASSWORD, "password") |
|||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb) |
|||
atom headers = NULL |
|||
headers = curl_slist_append(headers, "Content-Type: text/xml; charset=utf-8") |
|||
headers = curl_slist_append(headers, "SOAPAction: \"https://ameriwether.com/cgi-bin/info.pl/frobnicate\"") |
|||
headers = curl_slist_append(headers, "Accept: text/plain") -- Example output easier to read as plain text. |
|||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers) |
|||
-- Make the example URL work even if your CA bundle is missing. |
|||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false) |
|||
CURLcode res = curl_easy_perform(curl) |
|||
if res!=CURLE_OK then |
|||
printf(2, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)) |
|||
end if |
|||
curl_slist_free_all(headers) |
|||
curl_easy_cleanup(curl) |
|||
curl_global_cleanup()</lang> |
|||
{{out}} |
|||
<pre> |
|||
TCP Connection: |
|||
127.0.0.1:40056 > 127.0.0.1:443 |
|||
SSL Layer (TLSv1.2): |
|||
CIPHER=ECDHE-RSA-AES256-GCM-SHA384 |
|||
CIPHER_ALGKEYSIZE=256 |
|||
CIPHER_EXPORT=false |
|||
CIPHER_USEKEYSIZE=256 |
|||
CLIENT_VERIFY=NONE |
|||
COMPRESS_METHOD=NULL |
|||
SECURE_RENEG=true |
|||
SESSION_RESUMED=Initial |
|||
TLS_SNI=ameriwether.com |
|||
HTTP Request: |
|||
POST /cgi-bin/info.pl HTTP/1.1 |
|||
HTTP Headers: |
|||
Accept: text/plain |
|||
ContentLength: 411 |
|||
ContentType: text/xml; charset=utf-8 |
|||
Host: ameriwether.com |
|||
Soapaction: "https://ameriwether.com/cgi-bin/info.pl/frobnicate" |
|||
CGI Params: |
|||
POSTDATA=<?xml version="1.0" encoding="utf-8"?> |
|||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|||
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> |
|||
<soap:Body> |
|||
<frobnicate xmlns="http://example.com/frobnicate"> |
|||
<foo>'Ein'</foo> |
|||
<bar>>Zwei<</bar> |
|||
<baz>"Drei"</baz> |
|||
</frobnicate> |
|||
</soap:Body> |
|||
</soap:Envelope> |
|||
</pre> |
</pre> |
||