作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
URL url = new URL("http://maps.google.com/maps/api/geocode/json?address=1600%20Amphitheatre%20Parkway&sensor=false&client_id=my_client_id&key=my_key");
URLConnection urlConnection = url.openConnection();
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET");
InputStream in = httpURLConnection.getInputStream();
它给出的连接拒绝异常。
最佳答案
您忘记实际连接:
URL url = new URL("yoururl");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET");
try {
// open the connection and get results as InputStream.
httpURLConnection.connect();
InputStream in = httpURLConnection.getInputStream();;
// do more things
} finally {
httpURLConnection.disconnect();
}
您还可以修改 URL 编码方式以避免错误:
private String REQUEST_URL = "http://maps.google.com/maps/api/geocode/json";
private String address = "1600 Amphitheatre Parkway";
URL url = new URL(REQUEST_URL + "?address=" + URLEncoder.encode(address, "UTF-8") + "&sensor=false&client_id=my_client_id&key=my_key"););
关于java - 在java中使用地理编码(GoogleMapAPI)进行地址验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17403034/
URL url = new URL("http://maps.google.com/maps/api/geocode/json?address=1600%20Amphitheatre%20Parkwa
我想在 angularjs2 和 onsenUI2 中使用 GoogleMapAPI 自动完成功能,但我做不到。 这是我的代码: import { Component, NgModule, OnIni
我是一名优秀的程序员,十分优秀!