1

I want to upgrade my C# Web application from Google SafeBrowsing to WebRisk but I can't figure out what kind of changes I need to make in my code. Here is the code that worked in SafeBrowsing if an url typed in txtURL textbox is safe (which I predictably also couldn't figure out on my own without the help of this very website):

    protected async Task<GoogleSecuritySafebrowsingV4FindThreatMatchesResponse> GoogleCheckAsync()
    {
        var service = new SafebrowsingService(new BaseClientService.Initializer
        {
            ApplicationName = "MyApp",
            ApiKey = "mygoogleAPIkey"
        });

        var request = service.ThreatMatches.Find(new GoogleSecuritySafebrowsingV4FindThreatMatchesRequest()
        {
            Client = new GoogleSecuritySafebrowsingV4ClientInfo
            {
                ClientId = "Dotnet-client",
                ClientVersion = "1.5.2"
            },
            ThreatInfo = new GoogleSecuritySafebrowsingV4ThreatInfo()
            {
                ThreatTypes = new List<string> { "Malware", "Social_Engineering", "Unwanted_Software", "Potentially_Harmful_Application" },
                PlatformTypes = new List<string> { "Any_Platform" },
                ThreatEntryTypes = new List<string> { "URL" },
                ThreatEntries = new List<GoogleSecuritySafebrowsingV4ThreatEntry>
            {
                new GoogleSecuritySafebrowsingV4ThreatEntry
                {
                    Url = txtURL.Text
                }
            }
            }
        });;

        GoogleSecuritySafebrowsingV4FindThreatMatchesResponse response = await request.ExecuteAsync();
        return response;
    }

And I have the following code when user submits an url for checking:

GoogleSecuritySafebrowsingV4FindThreatMatchesResponse x = await GoogleCheckAsync();
string threatTypes;
if (x.Matches != null)
{
    foreach (GoogleSecuritySafebrowsingV4ThreatMatch match in x.Matches)
    {
         threatTypes += match.ThreatType + ";";
    }
}

0 Answers0