I am getting 404 when I am sending request for threatMatches:find

170 views
Skip to first unread message

Sneha Kalore

unread,
Jul 12, 2018, 9:47:02 AM7/12/18
to Google Safe Browsing API
following is my code:
/*String str = "{\"client\": {\"clientId\": \"clientId\","
                            + "\"clientVersion\": \"1.0.0\"},"
                                + "\"threatInfo\": {\"threatTypes\":      [\"MALWARE\", \"SOCIAL_ENGINEERING\", \"UNWANTED_SOFTWARE\", \"POTENTIALLY_HARMFUL_APPLICATION\"],"
                                + "\"platformTypes\":    [\"ANY_PLATFORM\"],"
                                + "\"threatEntryTypes\": [\"URL\", \"IP_RANGE\"],"
                                + "\"threatEntries\": ["
                                + "{\"url\": \"https://maps.google.com/maps?ll=37.405328,-121.90323&z=18&t=k&hl=en-US&gl=US&mapclient=apiv3\"},"
                                + "]"
                                + "}"
                                + "}";*/
 Map<String, Object> finalJson = new LinkedHashMap<>();
                        Map<String, Object> clientDetails = new LinkedHashMap<>();
                        clientDetails.put( "\"clientId\"", "\"clientId\"" );
                        clientDetails.put( "\"clientVersion\"", "\"1.0.0\"");
                        Map<String, Object> threatTypes = new HashMap<>();
                        threatTypes.put( "\"threatTypes\"", Arrays.asList("\"MALWARE\"", "\"SOCIAL_ENGINEERING\"", "\"UNWANTED_SOFTWARE\"", "\"POTENTIALLY_HARMFUL_APPLICATION\"") );
                        Map<String, Object> platformTypes = new HashMap<>();
                        platformTypes.put("\"platformTypes\"", Arrays.asList("\"ANY_PLATFORM\""));
                        Map<String, Object> threatEntryTypes = new HashMap<>();
                        threatEntryTypes.put("\"threatEntryTypes\"", Arrays.asList("\"URL\"", "\"IP_RANGE\""));
                        Map<String, Object> threatEntryUrl = new HashMap<>();
                        threatEntryUrl.put( "\"url\"", "\"https://developers.google.com/safe-browsing/v4/update-api\"");
                        Map<String, Object> threatEntries = new HashMap<>();
                        threatEntries.put("\"threatEntries\"", Arrays.asList( threatEntryUrl ));
                        finalJson.put( "\"client\"", clientDetails);
                        finalJson.put( "\"threatInfo\"", Arrays.asList(threatTypes, platformTypes, threatEntryTypes, threatEntries));
                        System.out.println("FinalJson"+ finalJson );
                         
                        Response googleSafeBrowserResponse  = given().baseUri("https://safebrowsing.googleapis.com/v4/" ).contentType( "application/json" ).body(finalJson).post("threatMatches:find?key=APIKey");
                        System.out.println( googleSafeBrowserResponse.statusCode() );
                        System.out.println( googleSafeBrowserResponse.asString() );

Getting following error:
404
<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/v4/threatMatches%3Afind?key=APIKey</code> was not found on this server.  <ins>That’s all we know.</ins>

I tried to run above code with both by passing body as str and by passing body as map, both the cases I am getting 404. I even tried to convert str into JsonObject and send request but still getting 404. When I ran same request with correct clientId through Jmeter, its working fine. But through restassured I am getting 404. I am not getting where I am going wrong. 


Sneha Kalore

unread,
Jul 12, 2018, 10:02:31 AM7/12/18
to Google Safe Browsing API
Note: I have not given exact apikey value in this post, but in actual code I am passing it. 

Eriq VanBibber

unread,
Jul 12, 2018, 7:37:39 PM7/12/18
to Google Safe Browsing API
Not sure of exactly how you're submitting your request, but as someone that has already been down this path before, i can offer some guidance.

not sure of what programming language is being used, but the url must be in the format of: https://safebrowsing.googleapis.com/v4/threatMatches:find?key=API_KEY HTTP/1.1

your "base" url does not seem complete as it is missing the ".../v4/threatMatches..." suffix.
the body of the POSTed request is to be only the JSON data.

i think your 'given().baseuri' statement should be reviewed a bit.

if you have fiddler or something similar, it helps to see what is actually being submitted to google's server's.

-Eriq

Sneha Kalore

unread,
Jul 13, 2018, 12:58:29 AM7/13/18
to Google Safe Browsing API
Hi Eriq,

Thanks for the response. I am writing code in Java Lang and using restassured to hit the safe browsing url. I tried to follow your instructions but I am still having hard time to go through. I am still getting 404. 

Following is the code I am trying.

String str = "{\"client\": {\"clientId\": \"462331279349-ugd8r2gnlk4th11nk4736gnvm8vclbun.apps.googleusercontent.com\","
                            + "\"clientVersion\": \"1.0.0\"},"
                                + "\"threatInfo\": {\"threatTypes\":      [\"MALWARE\", \"SOCIAL_ENGINEERING\", \"UNWANTED_SOFTWARE\", \"POTENTIALLY_HARMFUL_APPLICATION\"],"
                                + "\"platformTypes\":    [\"ANY_PLATFORM\"],"
                                + "\"threatEntryTypes\": [\"URL\", \"IP_RANGE\"],"
                                + "\"threatEntries\": ["
                                + "{\"url\": \"https://maps.google.com/maps?ll=37.405328,-121.90323&z=18&t=k&hl=en-US&gl=US&mapclient=apiv3\"},"
                                + "]"
                                + "}"
                                + "}";

                         
                        Response googleSafeBrowserResponse  = given().header("Content-Type","application/json").with().body(str).post("https://safebrowsing.googleapis.com/v4/threatMatches:find?key=AIzaSyCez9jn0dkv66_qYJOvnQG9wey4NaouIWo HTTP/1.1");
                        System.out.println( googleSafeBrowserResponse.statusCode() );
                        System.out.println( googleSafeBrowserResponse.asString() );

Sneha Kalore

unread,
Jul 13, 2018, 12:59:30 AM7/13/18
to Google Safe Browsing API
Even if I remove HTTP/1.1 I still get the same error.

Eriq VanBibber

unread,
Jul 13, 2018, 11:06:30 AM7/13/18
to Google Safe Browsing API
It could be something with your 'restassured' helper.

have you tried to use simply the built in Java features for HTTP?


have you try running fiddler or similar wire analyzer to see what your code is actually sending?

i can tell you from experience that google is not lying to you :).  there is something wrong with the way the http post is formatted or configured.  

-Eriq
Reply all
Reply to author
Forward
0 new messages