我正在尝试从我的黑莓模拟器测试一个http连接,但没有任何反应。我是否需要MDS模拟器来运行此应用程序? 我正在使用Eclipse Helios BlackBerry Java Plug-in 1.5.0。我还在我的系统中安装了黑莓JDE。
void getViaHttpConnection(String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
int rc;
try {
c = (HttpConnection)Connector.open(url);
RichTextField rt = new RichTextField("TEST LENGTH");
// Getting the response code will open the connection,
// send the request, and read the HTTP response headers.
// The headers are stored until requested.
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
is = c.openInputStream();
// Get the ContentType
String type = c.getType();
// Get the length and process the data
int len = (int)c.getLength();
if (len > 0) {
rt = new RichTextField("TEST LENGTH"+len);
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
}
} else {
rt = new RichTextField("GREATER LENGTH"+len);
int ch;
while ((ch = is.read()) != -1) {
}
}
} catch (ClassCastException e) {
throw new IllegalArgumentException("Not an HTTP URL");
} finally {
if (is != null)
is.close();
if (c != null)
c.close();
}
}
非常感谢帮助, 谢谢, VKS
答案 0 :(得分:4)
您需要运行MDS-CS模拟器以使用黑莓模拟器连接到互联网
答案 1 :(得分:1)
不,您不需要使用MDS-CS。
您可以将模拟器配置为使用PC的正常网络连接(绕过MDS-CS),方法是进入管理连接 - >设置Wi-Fi网络并连接到“默认WLAN网络”。