0
在我的黑莓OS 6.0的應用程序,我使用的HttpConnection發佈多個圖像文件, 這裏就是我想,User-Agent和Blackberry 6.0?
byte[] _dataToBePost = strPostData.getBytes();
String lineEnd = "\r\n";
String boundary = "----------------------------";
String boundaryStartBytes = "------------------------------\r\n";
byte[] startBytes = boundaryStartBytes.getBytes();
String boundaryEndBytes = "\r\n------------------------------\r\n";
byte[] endBytes = boundaryEndBytes.getBytes();
_httpConnection = (HttpConnection)Connector.open(url,Connector.READ_WRITE,true);
// Set the request method and headers
_httpConnection.setRequestMethod(HttpConnection.POST);
_httpConnection.setRequestProperty("If-Modified-Since","29 Oct 1999 19:43:31 GMT");
_httpConnection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
_httpConnection.setRequestProperty("Content-Language", "en-US");
if(PhotoToSend != null)
//if(AttachPhotos._vctAccPhotos.size() > 0)
{
String[] strAccidentPhoto = {"AccidentPhoto1", "AccidentPhoto2", "AccidentPhoto3", "AccidentPhoto4", "AccidentPhoto5"};
for(int i=0; i<5; i++)
{
String header = "Content-Disposition: form-data; name=\"file1\";filename=\""+ "AccidentPhoto"+ i +".jpg"+ "\"" + lineEnd + "Content-Type: application/octet-stream"+lineEnd+lineEnd;
byte[] composition = header.getBytes();
byte[] photoData = AttachPhotos.get(strAccidentPhoto[i]);
if(photoData != null)
{
_outputStream.write(startBytes);
_outputStream.write(composition);
_outputStream.write(photoData);
_outputStream.write(endBytes);
}
}
}
在我的代碼
我使用的User-Agent作爲資料/ MIDP-2.0配置/ CLDC-1.0。這是否使任何問題發佈多個文件?或者還有其他方式發佈數據。 該代碼沒有通過任何例外,但只啓用圖像文件。 我的代碼中缺少什麼?
我不相信操作系統會設置用戶代理,因爲它是HTTP客戶端的屬性,而不是操作系統。當您使用BlackBerry內置瀏覽器發出請求時,它會設置自己的用戶代理字符串,但是當您建立直接HTTP連接時,您可以自由選擇字符串。 如果您想模擬內置瀏覽器的用戶代理字符串,請參閱http://docs.blackberry.com/en/developers/deliverables/18169/HTTP_headers_sent_by_BB_Browser_1234911_11.jsp – gnuf 2011-03-30 16:43:39
@gnuf:您完全正確 - 只需檢查我的應用發送的內容 - 沒有User-Agent標頭。謝謝! – 2011-03-30 17:38:10