Google安全浏览HTTP POST – 403响应

我正在开发一个针对某些url查询Google安全浏览的程序,但我收到了一个我认为不应该收到的错误。

我发送以下请求:

2 http://google.com http://facebook.com 

通过POST到: https://sb-ssl.google.com/safebrowsing/api/lookup?client=api&apikey=[KEY]&appver=1.5.2&pver=3.1https://sb-ssl.google.com/safebrowsing/api/lookup?client=api&apikey=[KEY]&appver=1.5.2&pver=3.1

但是,我得到了403回复。

这是文档针对HTTP POST查找错误所说的内容:

服务器为POST请求生成以下HTTP错误代码:

•200:至少有一个查询过的URL在网络钓鱼,恶意软件或不需要的软件列表中匹配。 实际结果通过响应正文返回。

•204:查询的URL中没有一个与网络钓鱼,恶意软件或不需要的软件列表匹配,并且不返回任何响应正文。

•400:错误请求 – 未正确形成HTTP请求。

•401:未授权 – API密钥未经授权。

•503:服务不可用 – 服务器无法处理请求。 除了正常的服务器故障之外,这还可能表明客户端已被“限制”以发送太多请求。

响应代码403未列出,但我已收到它。

我已经对我的API密钥进行了三次检查,并确保为我的项目启用了API。 我正在使用服务器密钥,但我也尝试使用浏览器密钥。

我也试过做一个GET请求,这确实有效,但我无法让POST工作。 这是怎么回事?

这是我的代码:

 try { String baseURL="https://sb-ssl.google.com/safebrowsing/api/lookup"; String arguments = ""; arguments +=URLEncoder.encode("client", "UTF-8") + "=" + URLEncoder.encode("api", "UTF-8") + "&"; arguments +=URLEncoder.encode("apikey", "UTF-8") + "=" + URLEncoder.encode("[KEY]", "UTF-8") + "&"; arguments +=URLEncoder.encode("appver", "UTF-8") + "=" + URLEncoder.encode("1.5.2", "UTF-8") + "&"; arguments +=URLEncoder.encode("pver", "UTF-8") + "=" + URLEncoder.encode("3.1", "UTF-8"); // Construct the url object representing cgi script URL url = new URL(baseURL + "?" + arguments); // Get a URLConnection object, to write to POST method HttpURLConnection connect = (HttpURLConnection) url.openConnection(); connect.setRequestMethod("POST"); // Specify connection settings connect.setDoInput(true); connect.setDoOutput(true); // Get an output stream for writing OutputStream output = connect.getOutputStream(); PrintStream pout = new PrintStream (output); pout.print("2"); pout.println(); pout.print("http://www.google.com"); pout.println(); pout.print("http://www.facebook.com"); pout.close(); BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream())); String decodedString; while ((decodedString = in.readLine()) != null) { System.out.println("w: " + decodedString); } in.close(); } catch(Exception e) { e.printStackTrace(); } 

我发现了错误。 CGI参数不正确。 它应该是key而不是apikey 。 仍然很奇怪,你得到一个无证件的响应代码。