import
java.io.IOException;
import
org.apache.commons.httpclient.HttpClient;
import
org.apache.commons.httpclient.HttpException;
import
org.apache.commons.httpclient.HttpStatus;
import
org.apache.commons.httpclient.methods.GetMethod;
public
class
Test {
/**
*
@param
args
*/
public
static
void
main(String[] args) {
//
TODO Auto-generated method stub
GetMethod method
=
new
GetMethod(
"
http://api.telenav.com/tnapi/services/geoutil/geocode?apiKey=AQAAASNiwsIwf/////////8AAAABAAAAAQEAAAAQF55mB/t8b4u/xsTdcidXpAEAAAAOAwAAAA8AAAAXAAAAAQA=&firstLine=1130%20kifer%20rd,Sunnyvale,ca&country=US
"
);
HttpClient httpClient
=
new
HttpClient();
try
{
int
state
=
httpClient.executeMethod(method);
if
(state
==
HttpStatus.SC_OK) {
System.out.println(
"
OK
"
);
}
else
{
System.out.println(
"
Error
"
);
}
String result
=
method.getResponseBodyAsString();
System.out.println(result);
}
catch
(HttpException e) {
//
TODO Auto-generated catch block
e.printStackTrace();
}
catch
(IOException e) {
//
TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Maven 依赖
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.0.1</version>
</dependency>