Terry.Li-彬

虚其心,可解天下之问;专其心,可治天下之学;静其心,可悟天下之理;恒其心,可成天下之业。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  143 随笔 :: 344 文章 :: 130 评论 :: 0 Trackbacks
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>


posted on 2009-09-09 17:04 礼物 阅读(346) 评论(0)  编辑  收藏 所属分类: java