Google Safe Browsing API v4 - 空响应

时间:2016-12-20 19:16:30

标签: httprequest httpurlconnection httpresponse safe-browsing

尽管我检查了恶意网址(as outlined here),但空响应会从 Google Safe Browsing API v4 返回。

以下是我尝试过的代码:

String postURL = https://safebrowsing.googleapis.com/v4/threatMatches:find?key=API_KEY

String requestBody = "{" +
        "    \"client\": {" +
        "      \"clientId\":      \"twittersentidetector\"," +
        "      \"clientVersion\": \"1.0\"" +
        "    }," +
        "    \"threatInfo\": {" +
        "      \"threatTypes\":      [\"MALWARE\", \"SOCIAL_ENGINEERING\"]," +
        "      \"platformTypes\":    [\"ANY_PLATFORM\"]," +
        "      \"threatEntryTypes\": [\"URL\"]," +
        "      \"threatEntries\": [" +
        "        {\"url\": \"http://fileserver03.com\"}," +
        "        {\"url\": \"https://bing.com\"}," +
        "        {\"url\": \"https://yahoo.com\"}" +
        "      ]" +
        "    }" +
        "  }";

URL url = new URL(postURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();

con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("Content-Type", "application/json");

con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(requestBody);
wr.flush();
wr.close();

int responseCode = con.getResponseCode();
System.out.println("Response Code: " + responseCode);
System.out.println("Response Message: " + con.getResponseMessage());

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String output;
StringBuffer response = new StringBuffer();

while ((output = in .readLine()) != null) {
    response.append(output);
} in .close();

System.out.println("Response: " + response.toString());

以下是输出:

Response Code: 200
Response Message: OK
Response: {}

1 个答案:

答案 0 :(得分:5)

Google安全浏览API v4 会返回空的JSON,其中包含http代码200,如果网址未列出为“MALWARE”或您搜索的任何其他“threatTypes”。

因此,您可以尝试使用其他网址来查看已列出网址的响应情况。 试试这些:

http://goooogleadsence.biz/
http://activefile.ucoz.com/