Sample C# Code

// Setup the payload here. The structure of the payload itself will obviously
// change depending on which method/dataset combination we call and what
// parameters that method/dataset combination requires.
// Note the inclusion of "apirequest=" at the start of the Payload string.
// This ensures that the POST data will be received by the API as a
// proper POST name/value pair.

string XMLPayload = @"apirequest=<?xml version=""1.0"" encoding=""UTF-8"" ?> <data>
// The API Endpoint
string Endpoint = "";

// Initialize the webrequest object
WebRequest WebReq = WebRequest.Create(Endpoint);

// Set the method to POST, because we're sending POST data
WebReq.Method = "POST";

// And the content type to application/x-www-form-urlencoded, because we're emulating a
// standard web form.
WebReq.ContentType = "application/x-www-form-urlencoded";

// Since .NET sends POST data as a bytestream, we have to convert our payload to a byte array.
// This is convenient for finding the content-length anyway.
byte[] XMLByteArray = Encoding.UTF8.GetBytes(XMLPayload);
WebReq.ContentLength = XMLByteArray.Length;

// Get a handle to the request stream part of the WebRequest
// (This is the bytestream we'll be using to send our payload to the Maponics Spatial API).
// We could use BeginGetRequestStream() here, if we wanted to do this asynchronously.
// For simplification and the purposes of this code sample, we'll simply use the
// synchronous (blocking) GetRequestStream.
Stream RequestStream = WebReq.GetRequestStream();
// Send our data down the stream. (Merrily, merrily, merrily...)
// Since we used GetRequestStream, the code will block here and wait until the entire payload is sent.
RequestStream.Write(XMLByteArray, 0, XMLByteArray.Length);

// Close the stream

// That takes care of sending the request to the API. Now we have to grab the response.
// As before, we could use BeginGetResponse() if we wanted to do this asynchronously, but
// in this example, we'll just use GetResponse() and block until the API services the
// request and delivers our data

// Create the object that will handle the response
WebResponse WebRes = WebReq.GetResponse();

// Get a handle to the stream that will feed us our response data
Stream ResponseStream = WebRes.GetResponseStream();

// Create a streamreader to read the stream
StreamReader ResponseReader = new StreamReader(ResponseStream);

// Read the response into a string
string DataFromServer = ResponseReader.ReadToEnd();

// Clean up our objects

// You can process the returned response here. For the purposes of this sample, we'll just
// write the raw text to the console