Blackberry 所有代码都无法通过BIS建立http连接
我是开发黑莓应用程序的新手 在这三天里,我已经从RIM本身的论坛和教程中进行了搜索和学习。但是没有一个能解决我的问题 试试这个代码Blackberry 所有代码都无法通过BIS建立http连接,blackberry,httpconnection,Blackberry,Httpconnection,我是开发黑莓应用程序的新手 在这三天里,我已经从RIM本身的论坛和教程中进行了搜索和学习。但是没有一个能解决我的问题 试试这个代码 try { HttpConnection httpConnection=(HttpConnection)Connector.open(url); httpConnection.setRequestMethod(HttpConnection.GET); if(httpConnection.getResponseCode()==HttpConn
try {
HttpConnection httpConnection=(HttpConnection)Connector.open(url);
httpConnection.setRequestMethod(HttpConnection.GET);
if(httpConnection.getResponseCode()==HttpConnection.HTTP_OK)
{
InputStream is=httpConnection.openInputStream();
int ch;
StringBuffer buffer=new StringBuffer();
while((ch=is.read())!=-1)
{
buffer.append((char)ch);
}
}
} catch (IOException e) {
System.out.println("Exception From Thread"+e);
e.printStackTrace();
}
}
据我所知,为了使用BIS,您需要成为RIM合作伙伴(需要花钱)。
String url = "myURL";
try {
StreamConnection s = (StreamConnection)Connector.open(url);
InputStream input = s.openInputStream();
Dialog.inform("sblm byte");
byte[] data = new byte[256];
int len = 0;
StringBuffer raw = new StringBuffer();
Dialog.inform("stlh buat byte");
while( -1 != (len = input.read(data))) {
raw.append(new String(data, 0, len));
}
Dialog.inform("stlh while");
response = raw.toString();
Dialog.inform(response);
input.close();
s.close();
}
catch(Exception e) { }
try {
HttpConnection httpConnection=(HttpConnection)Connector.open(url);
httpConnection.setRequestMethod(HttpConnection.GET);
if(httpConnection.getResponseCode()==HttpConnection.HTTP_OK)
{
InputStream is=httpConnection.openInputStream();
int ch;
StringBuffer buffer=new StringBuffer();
while((ch=is.read())!=-1)
{
buffer.append((char)ch);
}
}
} catch (IOException e) {
System.out.println("Exception From Thread"+e);
e.printStackTrace();
}
}