将json数据发送到blackberry中的服务器
在我的应用程序中,我必须集成API。我没有得到如何检查互联网是否可用的代码。如何向服务器发送JSON数据。请帮帮我。在android中,我们在AsyncTask类中调用API。在黑莓手机中,我没有发现这样的问题 建议我一些链接或想法,以便我可以集成代码。我在谷歌上搜索。但没有得到结果。 我试过的是:将json数据发送到blackberry中的服务器,blackberry,java-me,Blackberry,Java Me,在我的应用程序中,我必须集成API。我没有得到如何检查互联网是否可用的代码。如何向服务器发送JSON数据。请帮帮我。在android中,我们在AsyncTask类中调用API。在黑莓手机中,我没有发现这样的问题 建议我一些链接或想法,以便我可以集成代码。我在谷歌上搜索。但没有得到结果。 我试过的是: JSONObject postData = new JSONObject(); postData.put("userId", "24"); postData.put("messageTime"
JSONObject postData = new JSONObject();
postData.put("userId", "24");
postData.put("messageTime","06:00:00");
postData.put("language", language[lang_Ocf.getSelectedIndex()]);
System.out.println("********json********"+postData);
ConnectionFactory conFactory = new ConnectionFactory();
ConnectionDescriptor conDesc = null;
try
{
conDesc = conFactory.getConnection(url+";deviceside=true");
}
catch(Exception e)
{
System.out.println(e.toString()+":"+e.getMessage());
}
String response = ""; // this variable used for the server response
// if we can get the connection descriptor from ConnectionFactory
if(null != conDesc)
{
try
{
HttpConnection connection = (HttpConnection)conDesc.getConnection();
//set the header property
connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty("Content-Length", Integer.toString(postData.length()));
connection.setRequestProperty("Content-Type","application/json");
OutputStream out = connection.openOutputStream();
out.write(postData.get);
out.flush();
out.close();
int responseCode = connection.getResponseCode();
if(responseCode == HttpConnection.HTTP_OK){
InputStream in = connection.openInputStream();
StringBuffer buf = new StringBuffer();
int read = -1;
while((read = in.read())!= -1)
buf.append((char)read);
response = buf.toString();
}
Dialog.inform(response);
connection.close();
} catch(Exception e) {
}
}
return response;
谢谢我解决了这个问题
错误:
错误:无法运行程序“jar”:CreateProcess Error=2,系统找不到指定的文件打包项目HelaBibleWhereUR失败(耗时10.715秒)
我只是将jar.exe放在jre-bin文件夹中的java-bin文件夹下 上面的代码有什么问题?@Nate:谢谢。我在模拟器上运行代码,但我并没有选择启动移动数据系统连接,它正在工作。现在的问题是我在不同的屏幕上实现了不同的api。现在我正在复制相同的代码,在运行它的时候给了我错误:无法运行程序“jar”:CreateProcess error=2,系统找不到指定的文件打包项目HelaBibleWhereUR失败(花了10.715秒)。我创建了新的简单类并将POST函数(字符串url)放入新类中,它给了我相同的错误。给我建议点什么看起来你解决了你的问题。如果您仍然希望在Android中使用类似于
AsyncTask
的功能,