0
我正在通過httpclient創建連接。但BlackBerry不支持Java httpclient類。代碼看起來像通過httpclient創建一個到服務器的連接?如何在BlackBerry中創建HTTPClient
我正在通過httpclient創建連接。但BlackBerry不支持Java httpclient類。代碼看起來像通過httpclient創建一個到服務器的連接?如何在BlackBerry中創建HTTPClient
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;
}
}
我認爲http://hc.apache.org/httpclient-3.x/是OP的意思。 – 2010-10-06 16:24:19
當您嘗試使用的HttpClient會發生什麼? – 2010-10-06 16:25:06