C#

The downloads page has a working .Net project which uses this approach. The readme file explains what project reference must be added. Feel free to try alternative approaches to what is done here.


HttpClient client = new HttpClient("https://services.cro.ie/cws/");

StringBuilder requestString = new StringBuilder();

// create the following few text boxes on your asp.net page:
// txtCompanyNum, txtCompanyName, txtAlpha, txtcompanyBusInd, txtAddress, txtSkip, txtMax
requestString.Append(String.Format("companies?"));
requestString.Append(txtCompanyNum.Text.Trim() == "" ? "" : String.Format("&company_num={0}", txtCompanyNum.Text));
requestString.Append(txtCompanyName.Text.Trim() == "" ? "" : String.Format("&company_name={0}", txtCompanyName.Text));
requestString.Append(txtAlpha.Text.Trim() == "" ? "" : String.Format("&alpha={0}", txtAlpha.Text));
requestString.Append(txtcompanyBusInd.Text.Trim() == "" ? "" : String.Format("&company_bus_ind={0}", txtcompanyBusInd.Text));
requestString.Append(txtAddress.Text.Trim() == "" ? "" : String.Format("&address={0}", txtAddress.Text));
requestString.Append(txtSkip.Text.Trim() == "" ? "&skip=0" : String.Format("&skip={0}", txtSkip.Text));
requestString.Append(txtMax.Text.Trim() == "" ? "&max=5" : String.Format("&max={0}", txtMax.Text));
requestString.Append("&htmlEnc=1");

string fullUrl = HttpUtility.HtmlEncode(String.Format("{0}{1}", servicesUrl, requestString.ToString()));


using (HttpRequestMessage request = new HttpRequestMessage("GET", requestString.ToString()))
{

    byte[] forEncoding = System.Text.ASCIIEncoding.ASCII.GetBytes("[email protected]:da093a04-c9d7-46d7-9c83-9c9f8630d5e0");
    
    string encodedCredentials = System.Convert.ToBase64String(forEncoding);
    
    request.Headers.Add("Authorization", string.Format("Basic {0}", encodedCredentials  ));

    request.Headers.Accept.AddString("application/xml");
    
    //  Or for Json:  request.Headers.Accept.AddString("application/json");
    
    using (HttpResponseMessage response = client.Send(request))
    {

        try
        {

            response.Content.LoadIntoBuffer();

            response.EnsureStatusIsSuccessful();

            response.Content.LoadIntoBuffer();

            List<Company> list = new List<Company>();

            list = response.Content.ReadAsDataContract<List<Company>>();

            //      Or if you used Json            
            //      list = response.Content.ReadAsJsonDataContract<List<Company>>();

            // Use a repeater or GridView... 
            repeater1.DataSource = list;
            repeater1.DataBind();

            response.Content.Dispose();
            
        }
        catch (Exception responseEx)
        {
            // Handle your error
        }
    }
}