|
Understanding the need for a quick and efficient data lookup API, we implemented
a simple HTTP-based lookup system using HTML Query String formatted request and
response text. This page contains programming examples illustrating the use of the
HTTP-based UNICER lookup API.
|
| Embedded JavaScript |
The following example illustrates how a JavaScript-based client can perform an embedded
lookup request for a UNICER record. The request is made using the standard WinHTTP.WinHTTPRequest
server object.
|
-
The first step is to configure the query URL, as shown in the example below:
var MyToken = "[your token here]";
var URL = "http://www.greenlightdata.com/Services/Unicer/Lookup/Data.ashx";
var Query = URL + "?token=" + MyToken + "&zip=00000&ssn=1234"
var HTTP = Server.CreateObject("WinHTTP.WinHTTPRequest.5.1");
-
Next, send the HTTP request to the GreenLight Data server:
HTTP.Open("GET", Query);
HTTP.Send();
-
The
ResponseText property of the HTTP object will contain the server
response. The client application should parse this string to retrieve the STATUS
parameter, and based on the status code parse the data values (if any):
var results = HTTP.ResponseText;
|
|
|
| C# .NET |
The following example illustrates how a .NET-based client can perform an embedded request for
a UNICER record, using C#. The request is made using the standard HttpWebRequest
and HttpWebResponse objects, defined in the System.Net namespace:
using System.IO;
using System.Net;
|
-
The first step is to configure the query URL, as shown in the example below:
string myToken = "[your token]";
string url = "http://www.greenlightdata.com/Services/Unicer/Lookup/Data.ashx";
string query = url + "?token=" + myToken + "&zip=00000&ssn=1234";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(query);
request.Method = "GET";
-
Next, send the HTTP request to the GreenLight Data server:
HttpWebResponse Response = (HttpWebResponse)request.GetResponse();
-
To obtain the response string, the client application must read the response data
through the
GetResponseStream() function of the HttpWebResponse
object. The results variable (in the example below) now contains
the full server response.
if (Response.StatusCode == HttpStatusCode.OK)
{
Stream stream = Response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string results = reader.ReadToEnd();
}
The client application should parse this string to retrieve the STATUS parameter, and
based on the status code parse the data values (if any).
|