我怎樣才能發送從作爲客戶端的工作到服務器,從服務器獲取信息使用它們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