Sample code for 30+ languages & platforms
Unicode C

Peoplevox WMS Authentication

See more HTTP Examples

Provides an example of a call to the Peoplevox WMS Authenticate using SOAP 1.1.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkStringBuilderW.h>
#include <C_CkCrypt2W.h>
#include <C_CkHttpRequestW.h>
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkXmlW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkStringBuilderW sbSoapXml;
    HCkCrypt2W crypt;
    const wchar_t *passwordBase64;
    int numReplacements;
    HCkHttpRequestW req;
    HCkHttpW http;
    HCkHttpResponseW resp;
    HCkXmlW xmlResponse;
    const wchar_t *detail;

    success = FALSE;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Sends a POST that looks like this:

    // 	POST /PEOPLEVOX_CLIENT_ID/resources/integrationservicev4.asmx HTTP/1.1
    // 	Content-Type: text/xml;charset=UTF-8
    // 	SOAPAction: http://www.peoplevox.net/Authenticate
    // 	Content-Length: (automatically computed and added by Chilkat)
    // 	Host: qac.peoplevox.net
    // 
    // 	<?xml version="1.0" encoding="utf-8"?>
    // 	<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:peop="http://www.peoplevox.net/">
    // 	   <soapenv:Header/>
    // 	   <soapenv:Body>
    // 	      <peop:Authenticate>
    // 	         <peop:clientId>PEOPLEVOX_CLIENT_ID</peop:clientId>
    // 	         <peop:username>PEOPLEVOX_USERNAME</peop:username>
    // 	         <peop:password>PEOPLEVOX_BASE64_PASSWORD</peop:password>
    // 	      </peop:Authenticate>
    // 	   </soapenv:Body>
    // 	</soapenv:Envelope>
    // 

    sbSoapXml = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbSoapXml,L"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    CkStringBuilderW_Append(sbSoapXml,L"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:peop=\"http://www.peoplevox.net/\">");
    CkStringBuilderW_Append(sbSoapXml,L"   <soapenv:Header/>");
    CkStringBuilderW_Append(sbSoapXml,L"   <soapenv:Body>");
    CkStringBuilderW_Append(sbSoapXml,L"      <peop:Authenticate>");
    CkStringBuilderW_Append(sbSoapXml,L"         <peop:clientId>PEOPLEVOX_CLIENT_ID</peop:clientId>");
    CkStringBuilderW_Append(sbSoapXml,L"         <peop:username>PEOPLEVOX_USERNAME</peop:username>");
    CkStringBuilderW_Append(sbSoapXml,L"         <peop:password>PEOPLEVOX_BASE64_PASSWORD</peop:password>");
    CkStringBuilderW_Append(sbSoapXml,L"      </peop:Authenticate>");
    CkStringBuilderW_Append(sbSoapXml,L"   </soapenv:Body>");
    CkStringBuilderW_Append(sbSoapXml,L"</soapenv:Envelope>");

    // Base64 encode the password and update the SOAP XML.
    crypt = CkCrypt2W_Create();
    passwordBase64 = CkCrypt2W_encodeString(crypt,L"PEOPLEVOX_PASSWORD",L"utf-8",L"base64");
    numReplacements = CkStringBuilderW_Replace(sbSoapXml,L"PEOPLEVOX_BASE64_PASSWORD",passwordBase64);

    req = CkHttpRequestW_Create();
    CkHttpRequestW_putHttpVerb(req,L"POST");
    CkHttpRequestW_putSendCharset(req,TRUE);
    CkHttpRequestW_putCharset(req,L"utf-8");
    CkHttpRequestW_AddHeader(req,L"Content-Type",L"text/xml");
    CkHttpRequestW_AddHeader(req,L"SOAPAction",L"http://www.peoplevox.net/Authenticate");
    CkHttpRequestW_putPath(req,L"/PEOPLEVOX_CLIENT_ID/resources/integrationservicev4.asmx");
    success = CkHttpRequestW_LoadBodyFromString(req,CkStringBuilderW_getAsString(sbSoapXml),L"utf-8");

    http = CkHttpW_Create();
    CkHttpW_putFollowRedirects(http,TRUE);

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpSReq(http,L"qac.peoplevox.net",443,TRUE,req,resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkStringBuilderW_Dispose(sbSoapXml);
        CkCrypt2W_Dispose(crypt);
        CkHttpRequestW_Dispose(req);
        CkHttpW_Dispose(http);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    // We should expect a 200 response if successful.
    if (CkHttpResponseW_getStatusCode(resp) != 200) {
        wprintf(L"Response StatusCode = %d\n",CkHttpResponseW_getStatusCode(resp));
        wprintf(L"Response StatusLine: %s\n",CkHttpResponseW_statusLine(resp));
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        CkStringBuilderW_Dispose(sbSoapXml);
        CkCrypt2W_Dispose(crypt);
        CkHttpRequestW_Dispose(req);
        CkHttpW_Dispose(http);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    // A successful response returns this XML:

    // <?xml version="1.0" encoding="utf-8" ?>
    // <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">
    //     <soap:Body>
    //         <AuthenticateResponse xmlns="http://www.peoplevox.net/">
    //             <AuthenticateResult>
    //                 <ResponseId>0</ResponseId>
    //                 <TotalCount>1</TotalCount>
    //                 <Detail>PEOPLEVOX_CLIENT_ID,7fe13431-c67f-4d52-bcfd-b60fbfa3b0ca</Detail>
    //                 <Statuses />
    //                 <ImportingQueueId>0</ImportingQueueId>
    //                 <SalesOrdersToDespatchIds />
    //             </AuthenticateResult>
    //         </AuthenticateResponse>
    //     </soap:Body>
    // </soap:Envelope>
    // 

    xmlResponse = CkXmlW_Create();
    success = CkXmlW_LoadXml(xmlResponse,CkHttpResponseW_bodyStr(resp));
    wprintf(L"%s\n",CkXmlW_getXml(xmlResponse));

    // Show how to get the Detail, which must be the ClientId,SessionId
    detail = CkXmlW_chilkatPath(xmlResponse,L"soap:Body|AuthenticateResponse|AuthenticateResult|Detail|*");
    wprintf(L"Detail = %s\n",detail);


    CkStringBuilderW_Dispose(sbSoapXml);
    CkCrypt2W_Dispose(crypt);
    CkHttpRequestW_Dispose(req);
    CkHttpW_Dispose(http);
    CkHttpResponseW_Dispose(resp);
    CkXmlW_Dispose(xmlResponse);

    }