黑莓 http 连接需要任何模拟器吗?
我正在尝试从我的黑莓模拟器测试 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();
}
}
非常感谢帮助, 谢谢, 维克斯
I'm trying to test an http connection from my blackberry simulator but nothing happens. Do I need an MDS simulator for running this App?
I am using Eclipse Helios BlackBerry Java Plug-in 1.5.0. I've also installed blackberry JDE in my system.
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();
}
}
Help is highly appreciated,
Thanks,
VKS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要运行 MDS-CS 模拟器才能使用黑莓模拟器连接到互联网
You need to run the MDS-CS simulator to connect to the internet using a blackberry simulator
不,您不需要使用 MDS-CS。
您可以通过转到“管理连接”->“设置 Wi-Fi 网络”并连接到“默认 WLAN 网络”,将模拟器配置为使用 PC 的正常网络连接(绕过 MDS-CS)。
No, you don't need to use MDS-CS.
You can configure the simulator to use your PC's normal network connection (bypassing MDS-CS) by going to Manage Connections->Set Up Wi-Fi Network and connecting to "Default WLAN Network".