gpt4 book ai didi

java - Blackberry http 连接需要任何模拟器吗?

转载 作者:行者123 更新时间:2023-11-30 06:33:01 24 4
gpt4 key购买 nike

我正在尝试从我的黑莓模拟器测试 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

最佳答案

您需要运行 MDS-CS 模拟器才能使用黑莓模拟器连接到互联网

关于java - Blackberry http 连接需要任何模拟器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8431464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com