日期:2014-05-20  浏览次数:20820 次

帮我看看这个程序的问题
import   java.net.HttpURLConnection;
import   java.net.URL;
import   java.io.*;

import   org.apache.log4j.Logger;
import   org.apache.log4j.PropertyConfigurator;

public   class   HttpRequest   {

private   static   Logger   elogger   =   Logger.getLogger( "Prosten_ERROR ");

public   String   getArea(String   phone)   {

HttpURLConnection   conn   =   null;
String   area   =   " ";
String   urlStr   =   "http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19 ";
try   {
URL   url   =   new   URL(urlStr);
conn   =   (HttpURLConnection)url.openConnection();

        conn.setRequestProperty( "accept ", "image/gif,   image/x-xbitmap,   image/jpeg,   image/pjpeg,   application/x-shockwave-flash,   application/vnd.ms-excel,   application/vnd.ms-powerpoint,   application/msword,   */* ");
        conn.setRequestProperty( "accept-language ", "zh-cn ");
        conn.setRequestProperty( "accept-encoding ", "gzip,   deflate ");
        conn.setRequestProperty( "user-agent ", "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.1;   Avant   Browser;   InfoPath.2;   InfoPath.1;   Alexa   Toolbar) ");
        conn.setRequestProperty( "connection ", "Keep-Alive ");
        conn.setRequestProperty( "Content-Type ", "application/x-www-form-urlencoded ");
        conn.setRequestProperty( "Content-Length ",String.valueOf(urlStr.length()));
       
        conn.setRequestMethod( "POST ");
        conn.setDoOutput(   true   );
        conn.setDoInput(   true   );
        String   phoneNo= "phoneNo= "+phone;

        conn.getOutputStream().write(phoneNo.getBytes());
        conn.getOutputStream().flush();
        conn.getOutputStream().close();  
       
        String   inputLine;
        InputStream   is   =   conn.getInputStream();
                BufferedReader   br   =   new   BufferedReader(new   InputStreamReader(is));
        while   ((inputLine   =   br.readLine())   !=   null   )       {
          area   +=   inputLine;
          System.out.println(inputLine);
        }  
        br.close();

}catch   (Exception   ex)     {
elogger.error( "Error: "   +   ex.getMessage());
        return   null;
}
finally
        {
            if(conn!=null)
            conn.disconnect();
                          }