Pesquisar um URI

Crie um cliente do Webrisk e pesquise um URI.

Exemplo de código

Java

public static SearchUrisResponse searchUriExample(String uri) throws IOException {
  // create-webrisk-client
  try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
    // Query the url for a specific threat type
    SearchUrisRequest searchUrisRequest =
        SearchUrisRequest.newBuilder().addThreatTypes(ThreatType.MALWARE).setUri(uri).build();
    SearchUrisResponse searchUrisResponse = webRiskServiceClient.searchUris(searchUrisRequest);
    webRiskServiceClient.shutdownNow();
    if (!searchUrisResponse.getThreat().getThreatTypesList().isEmpty()) {
      System.out.println("The URL has the following threat : ");
      System.out.println(searchUrisResponse);
    } else {
      System.out.println("The URL is safe!");
    }

    return searchUrisResponse;
  }
}

A seguir

Para pesquisar e filtrar exemplos de código de outros produtos do Google Cloud, consulte o navegador de exemplos do Google Cloud.