For a deeper look into our World Check One API, look into:

Overview |  Quickstart |  Documentation |  Downloads

question

Upvotes
31 2 5 7

World-Check One API profile reference C# code using HttpWebRequest not working

Hi. I'm trying to run a profile check on the World-Check One API in C# but I can't get the following code to work. Any help would be appreciated:

            DateTime dateValue = DateTime.UtcNow;
            
            string apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            string apisecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            string gatewayurl = "/v1/";
            string gatewayhost = "rms-world-check-one-api-pilot.thomsonreuters.com";
            string requestendpoint = "https://rms-world-check-one-api-pilot.thomsonreuters.com/v1/reference/profile/e_tr_wci_2221";

            string date = dateValue.ToString("R");

            string dataToSign = "(request-target): get " + gatewayurl + "reference/profile/" + HttpUtility.UrlEncode("e_tr_wci_2221") + "\n" +
            "host: " + gatewayhost + "\n" + // no https only the host name
            "date: " + date + "\n"; // GMT date as a string

            string hmac = generateAuthHeader(dataToSign, apisecret);
            string authorisation = "Signature keyId=\"" + apikey + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\"" + hmac + "\"";

            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(requestendpoint);

            WebReq.Method = "GET";
            WebReq.Headers.Add("Authorization", authorisation);
            WebReq.Headers.Add("Date", date);
            //WebReq.Headers.Add("Cache-Control", "no-cache");
            WebReq.Date = dateValue; // use datetime value GMT time            

            HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();//code execution fails here
            Stream Answer = WebResp.GetResponseStream();
            StreamReader reader = new StreamReader(Answer);

            string html = reader.ReadToEnd();

Thanks.

world-checkworld-check-onereference-id
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nevermind, I found the error, Thx.

1 Answer

· Write an Answer
Upvotes
4.2k 8 5 6

@gerhardtm

It would be great if you can share the solution with us to help our other community members.


Thanks.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.