我有这段代码:
package sig;
import org.json.JSONObject;
public class MyService extends java.lang.Object{
public JSONObject getLocationInfo( double lat, double lng) {
HttpGet httpGet = new HTTP("http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false");
HttpClient client = new DefaultHttpClient();
HttpResponse response;
StringBuilder stringBuilder = new StringBuilder();
try {
response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
int b;
while ((b = stream.read()) != -1) {
stringBuilder.append((char) b);
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject = new JSONObject(stringBuilder.toString());
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject;
}
}
但HttpGet
中的错误,我应该使用哪个库才能使用HttpGet
,谢谢!
答案 0 :(得分:0)
使用httpcomponents-client jar。
它有Maven条目:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.1</version>
</dependency>