2010-10-06 47 views

回答

0
import java.io.InputStream; 

import javax.microedition.io.Connector; 
import javax.microedition.io.StreamConnection; 

public class HTTPClient { 
    public static String getPage(String url) { 
     String response = ""; 

     try { 
      StreamConnection s = (StreamConnection)Connector.open(url); 

      InputStream input = s.openInputStream(); 

      byte[] data = new byte[256]; 
      int len = 0; 
      StringBuffer raw = new StringBuffer(); 

      while(-1 != (len = input.read(data))) { 
       raw.append(new String(data, 0, len)); 
      } 

      response = raw.toString(); 

      input.close(); 
      s.close(); 
     } catch(Exception e) { } 

     return response; 
    } 
} 
+2

我認爲http://hc.apache.org/httpclient-3.x/是OP的意思。 – 2010-10-06 16:24:19

相關問題