【问题标题】:Google Safe Browsing API v4 - Empty responseGoogle 安全浏览 API v4 - 空响应
【发布时间】:2016-12-20 19:16:29
【问题描述】:

尽管我检查了一个恶意 URL (http://fileserver03.com),但从 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: {}

【问题讨论】:

    标签: httprequest httpurlconnection httpresponse safe-browsing


    【解决方案1】:

    如果 URL 未列出为“MALWARE”或您搜索的任何其他“threatTypes”,

    Google Safe Browsing API v4 将返回空 JSON 和 http 代码 200。 p>

    因此,您可以尝试其他 URL,以查看 列出的 URL 的响应情况。 试试这些:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 2012-09-09
    相关资源
    最近更新 更多