有什么更好的将WBXML数据发送到Web服务器的方法?

时间:2020-03-06 14:43:30  来源:igfitidea点击:

请帮我以WBXML格式将数据从Mobile appication发送到Web Server吗?我有一些将xml转换为wbxml的方法,但没有获得如何以有效方式将其发送到Web服务器的信息?

解决方案

我不确定我是否完全理解问题,但是这里...

我们需要使用POST HTTP请求,并将WBXML数据写入连接对象输出流。这是一个简单的示例,显然,我们需要更多代码才能使其真正起作用:

byte[] wbxml = getMyWbxmlData();
HttpConnection conn = (HttpConnection)Connector.open("http://myserver.com/mywbxmlhandler");
conn.setRequestMethod(HttpConnection.POST);
OutputStream output = conn.openOutputStream();
output.write(wbxml);
InputStream input = conn.openInputStream(); // This will flush the outputstream
// Do response processing

前提是WBXML已经包含了序言,例如版本号,公共代码页标识符等。