2011-09-22 162 views
1

我一直在處理BlackBerry發佈請求,並且請求正在發送,但參數似乎不是。這裏是我的代碼:http發送請求不在黑莓5.0中發送參數

 HttpConnection httpConnection = (HttpConnection) Connector.open(url); 
     httpConnection.setRequestMethod(HttpConnection.POST); 
     httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 

     URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false); 
     encPostData.append("time", "1314144000"); 

     System.out.println("url: " + httpConnection.getURL()); 

     byte[] postData = encPostData.toString().getBytes("UTF-8"); 

     System.out.println("post data: " + encPostData.toString()); 
     httpConnection.setRequestProperty("Content-length", String.valueOf(postData.length)); 

     System.out.println("url: " + httpConnection.getURL()); 
     System.out.println("message:" + httpConnection.getResponseMessage()); 

     OutputStream os = httpConnection.openOutputStream(); 
     os.write(postData); 
     os.flush(); 
     os.close(); 

我從服務器(我們設置)得到的響應是我們沒有發送時間戳。我的問題有沒有問題

encPostData.append("time", "1314144000"); 

code?

回答

5

在寫入發佈數據之前,您對getResponseMessage()的調用在連接寫入任何內容之前強制進行響應。

System.out.println("message:" + httpConnection.getResponseMessage()); 

移動到最後,輸出流數據被寫入後,我認爲它會對你更好。

0

請在讀寫HTTP連接mode.Might是毫無模式鏈接問題進行HTTP連接

HttpConnection connection = (HttpConnection) Connector.open("url", Connector.READ_WRITE); 

見下面鏈接,使HTTP連接。 blackberry server connection problem

+0

這並沒有幫助... – coder

+1

曾經評論System.out.println(「message:」+ httpConnection.getResponseMessage());行和check.i檢查你的代碼它爲我工作 – koti

+0

我剛剛評論了行System.out.println(「message:」+ httpConnection.getResponseMessage());出來,但它仍然沒有工作。正在建立連接,但服務器沒有獲取數據。 – coder