在 BlackBerry 中访问互联网执行 POST 的不同方式
我正在制作一个应用程序来在其中执行 POST 操作。如下所示,
//private boolean x = false;
url = "http://domain.com/login";
InputStream inputStream = null;
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(url);
if (connDesc != null)
{
HttpConnection httpConn;
httpConn = (HttpConnection)connDesc.getConnection();
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
encPostData.append("username",username);
encPostData.append("password",password);
byte[] postData = encPostData.toString().getBytes("UTF-8");
httpConn.setRequestProperty("Content-Length", String.valueOf(postData.length));
httpConn.openOutputStream().write(encPostData.getBytes());
try
{
int Response = httpConn.getResponseCode();
System.out.println("Response Code = "+Response+httpConn.getResponseCode());
if (Response == 200)
{
System.out.println("Response Code = "+Response+httpConn.getResponseCode());
inputStream = httpConn.openInputStream();
byte[] responseData = new byte[10000];
int length = 0;
StringBuffer rawResponse = new StringBuffer(10000);
while (-1 != (length = inputStream.read(responseData)))
{
rawResponse.append(new String(responseData, 0, length));
}
replyMessage = rawResponse.toString();
key = replyMessage.substring(12, replyMessage.length()-2);
}
else if(Response == 500)
{
Dialog.alert("User Details Incorrect");
}
else
{
System.out.println(Response);
}
}
catch (IOException e)
{
Dialog.alert("Connection not established");
}
}
else
{
Dialog.alert("Connection not established");
}
return key;
我现在想知道这在哪种类型的服务下可以工作。 如果没有 gprs/3g 但有 wifi 连接,我想让我的应用程序工作.. 或者反过来也可以..
有没有办法首先识别可用的网络,然后选择一个网络进行通信。
我很感谢在这方面的任何帮助..
谢谢你,
I am making an application to perform an POST action in it . Which is shown below
//private boolean x = false;
url = "http://domain.com/login";
InputStream inputStream = null;
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(url);
if (connDesc != null)
{
HttpConnection httpConn;
httpConn = (HttpConnection)connDesc.getConnection();
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
encPostData.append("username",username);
encPostData.append("password",password);
byte[] postData = encPostData.toString().getBytes("UTF-8");
httpConn.setRequestProperty("Content-Length", String.valueOf(postData.length));
httpConn.openOutputStream().write(encPostData.getBytes());
try
{
int Response = httpConn.getResponseCode();
System.out.println("Response Code = "+Response+httpConn.getResponseCode());
if (Response == 200)
{
System.out.println("Response Code = "+Response+httpConn.getResponseCode());
inputStream = httpConn.openInputStream();
byte[] responseData = new byte[10000];
int length = 0;
StringBuffer rawResponse = new StringBuffer(10000);
while (-1 != (length = inputStream.read(responseData)))
{
rawResponse.append(new String(responseData, 0, length));
}
replyMessage = rawResponse.toString();
key = replyMessage.substring(12, replyMessage.length()-2);
}
else if(Response == 500)
{
Dialog.alert("User Details Incorrect");
}
else
{
System.out.println(Response);
}
}
catch (IOException e)
{
Dialog.alert("Connection not established");
}
}
else
{
Dialog.alert("Connection not established");
}
return key;
i am now wondering under which type of service would this work.
I want to make my application work if there be no gprs/ 3g but have a wifi connection ..
Or the other way around too ..
Is there anyways to identify first the networks available n later pick a network for communication.
I appreciate any help in this regard..
Thank You,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
花一些时间阅读 TransportInfo javadoc
Take some time to read TransportInfo javadoc