Both examples below require USING statements for System.IO and System.Net. A full example is also available for download.

GET Method Example

{
<div class="code">HttpWebRequest myRequest;// Prepare the request
// (GET does not allow any enclosed fields,
// so send API key and any params through querystring)
myRequest = (HttpWebRequest)WebRequest.Create(
"http://emailapi.dynect.net/rest/json/senders?apikey=[YOUR_API_KEY]");
myRequest.Method = "GET";

// Invoke the request
WebResponse response = myRequest.GetResponse();

// Assemble result and return it
StreamReader responseStream = new StreamReader(response.GetResponseStream());
string retVal = responseStream.ReadToEnd();
responseStream.Close();
response.Close();

// Insert code to parse response here

</div>
}

POST Method Example

{
<div class="code">// Prepare the request
myRequest = (HttpWebRequest)WebRequest.Create(
"http://emailapi.dynect.net/rest/json/senders");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";// Assemble string of parameters, delimited by ampersand (&)
string qs = "apikey=[YOUR_API_KEY]&emailaddress=example@domain.com";

// (PUT, POST, DELETE take enclosed fields,
// so send API key and others through data stream)
byte[] fieldData = Encoding.UTF8.GetBytes(qs);
myRequest.ContentLength = fieldData.Length;
Stream fieldStream = myRequest.GetRequestStream();
fieldStream.Write(fieldData, 0, fieldData.Length);
fieldStream.Close();

// Invoke (via response to get response back)
WebResponse response = myRequest.GetResponse();

// Assemble result into HTML and return it
StreamReader responseStream = new StreamReader(response.GetResponseStream());
string retVal = responseStream.ReadToEnd();
responseStream.Close();
response.Close();

// Insert code to parse response here

</div>
}