我怎样才能发送从作为客户端的工作到服务器,从服务器获取信息使用它们BB应用 我使用黑莓日食windows下的黑莓应用程序JSON请求7发送JSON请求
我尝试这个代码
public void loginRequest() throws IOException, JSONException{
HttpConnection c = null;
InputStream is = null;
int rc;
JSONObject postObject = new JSONObject();
postObject.put("method", method);
//postObject.put("params", Parameters);
try{
c = (HttpConnection)Connector.open(urlPath);
// Set the request method and headers
c.setRequestMethod(HttpConnection.GET);
c.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
c.setRequestProperty("Content-Length", "" + (postObject.toString().length() - 2));
c.setRequestProperty("method", "GET");
// 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 length and process the data
int len = (int)c.getLength();
if (len > 0){
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;
}
//Get the JSON String
System.out.println(new String(data));
}
else{
int ch;
while ((ch = is.read()) != -1){
//TODO
/*
process((byte)ch);
*/
}
}
}catch (ClassCastException e){
throw new IllegalArgumentException("Not an HTTP URL");
}finally {
if (is != null)
is.close();
if (c != null)
c.close();
}
}
i当模拟器距离(RC = c.getResponseCode();)调用由运行方法该方法在一个线程
运行的代码STO PS
我调试代码,当它与此错误
本地连接后〜120000
任何帮助
我试试你的答案,但你重新启动这并没有解决我的问题 启用MDS,但我仍然有错误 – 2012-02-18 10:00:46
模拟器使MDS后(关闭并重新运行和应用程序)?除非模拟器重新启动,否则无法工作。 – mrvincenzo 2012-02-18 10:11:51
我重新启动了eclipse和模拟器,并且仍然出现错误(BbiAuth:ERR:net.rim.device.api.crypto.bbiauth.BbiAuthException:没有配置BBAuth服务记录)此错误在程序崩溃后出现在模拟器的输出日志中 – 2012-02-18 10:32:14