Sample code for 30+ languages & platforms
JavaScript

Send HTTPS POST with XML Body

See more HTTP Examples

Demonstrates how to send an HTTP (or HTTPS) POST where the body of the request is XML.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

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

var http = new CkHttp();

var strXml = "<TransactionSetup xmlns=\"https://xyz.com\"><Credentials><AccountID>XXX</AccountID></Credentials></TransactionSetup>";

// Maybe you need other headers?
http.SetRequestHeader("Accept","application/xml");

var resp = new CkHttpResponse();
success = http.HttpStr("POST","https://www.somewebsite.com/",strXml,"utf-8","application/xml",resp);
if (success == false) {
    console.log(http.LastErrorText);
    return;
}

// Examine the response status code:
console.log("response status code = " + resp.StatusCode);

// Examine the response body:
console.log("response body: " + resp.BodyStr);