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