Reputation: 53
Here is the code to see which url is safe for browsing.I have used google api for it. The problem i am facing is I am not able to get SafeBrowsing class object to hit the given url. So kindly see if anyone have solution.
public static void main(final String[] args) {
try {
final String baseURL = "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=xxx";
final URL url = new URL(baseURL);
// Get a URLConnection object, to write to POST method
final HttpURLConnection connect = (HttpURLConnection) url.openConnection();
connect.setRequestMethod("POST");
connect.setRequestProperty("Content-Type", "application/json");
// Specify connection settings
connect.setDoInput(true);
connect.setDoOutput(true);
final ClientInfo clientInfo = new Ggooggle().getClientInfo();
final ThreatInfo threatInfo = new Ggooggle().getThreatInfo();
final FindThreatMatchesRequest request = new FindThreatMatchesRequest();
request.setClient(clientInfo);
request.setThreatInfo(threatInfo);
Upvotes: 1
Views: 698
Reputation: 89
Try this.
public final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
public static final JacksonFactory GOOGLE_JSON_FACTORY = JacksonFactory.getDefaultInstance();
Safebrowsing.Builder safebrowsingBuilder = new Safebrowsing.Builder(httpTransport, GOOGLE_JSON_FACTORY, null);
Safebrowsing safebrowsing = safebrowsingBuilder.build();
FindThreatMatchesResponse findThreatMatchesResponse = safebrowsing.threatMatches().find(findThreatMatchesRequest).setKey(GOOGLE_API_KEY).execute();
List<ThreatMatch> threatMatches = findThreatMatchesResponse.getMatches();
if (threatMatches != null && threatMatches.size() > 0) {
for (ThreatMatch threatMatch : threatMatches) {
threatUrls.add(threatMatch.getThreat().getUrl());
}
}
The full sample codes: https://github.com/kalinchih/java_google_safebrowsing_v4
Upvotes: 1