访问谷歌API链接时收到错误

时间:2013-07-02 10:24:20

标签: java google-api

我在jsp中有一个ui,有两个字段是一个文本框,另一个是按钮。 想要在按钮单击后显示带有文本框值的位置建议 在纯Java代码中,不使用任何java脚本

我在java中使用下面的代码

System.setProperty("http.proxyHost","my proxy") ;
System.setProperty("http.proxyPort", "8080") ;

URL u = new URL("https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&sensor=true&key=KEY_AWESOMENESS");

HttpURLConnection con = (HttpURLConnection) u.openConnection();
//
// it's not the greatest idea to use a sun.misc.* class
// Sun strongly advises not to use them since they can
// change or go away in a future release so beware.
//

di = new DataInputStream(con.getInputStream());
while(-1 != di.read(b,0,1)) {
    System.out.print(new String(b));
}

给出一些错误,如

java.io.IOException: Server returned HTTP response code: 407 for URL: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&sensor=true&key=KEY_AWESOMENESS"
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)

任何人都可以帮助我。

0 个答案:

没有答案