【发布时间】:2024-01-17 14:05:02
【问题描述】:
我们刚刚开始编写黑莓应用程序,遇到了奇怪的情况。我们的应用适用于移动互联网(GPRS、3G、EDGE),但无法使用 wifi 连接。
我已尝试更改所有设置。但通常它只是“隧道故障”或“连接超时”错误。 HTTPDemo 示例也是如此。
有人可以帮忙解释一下黑莓和 WiFi 是什么吗?
StreamConnection s = null; s = (StreamConnection)Connector.open(getUrl() +";interface=wifi"); HttpConnection httpConn = (HttpConnection)s;
int status = httpConn.getResponseCode();
if (status == HttpConnection.HTTP_OK)
{
// Is this html?
String contentType = httpConn.getHeaderField(HEADER_CONTENTTYPE);
boolean htmlContent = (contentType != null && contentType.startsWith(CONTENTTYPE_TEXTHTML));
InputStream input = s.openInputStream();
byte[] data = new byte[256];
int len = 0;
int size = 0;
StringBuffer raw = new StringBuffer();
while ( -1 != (len = input.read(data)) )
{
// Exit condition for the thread. An IOException is
// thrown because of the call to httpConn.close(),
// causing the thread to terminate.
if ( _stop )
{
httpConn.close();
s.close();
input.close();
}
raw.append(new String(data, 0, len));
size += len;
}
raw.insert(0, "bytes received]\n");
raw.insert(0, size);
raw.insert(0, '[');
content = raw.toString();
if ( htmlContent )
{
content = prepareData(raw.toString());
}
input.close();
}
else
{
content = "response code = " + status;
}
s.close();
}
catch (IOCancelledException e)
{
System.out.println(e.toString());
return;
}
catch (IOException e)
{
errorDialog(e.toString());
return;
}
【问题讨论】:
标签: blackberry wifi