只需使用内置的 Titanium 实用程序将您的数据编码为 base64:
// Encode your data
var data = Titanium.Utils.base64encode(dataToSendToWebService);
现在使用 HTTPClient 发送它:
var postDataTOServer = Ti.Network.createHTTPClient({
onload : function(e) {
// If the service returns successfully : true, or false
var isUserAllowed = this.responseText;
},
onerror : function(e) {
// Web service failed for some reason
Ti.API.info(this.responseText);
Ti.API.info('webservice failed with message : ' + e.error);
}
});
// POST
postDataTOServer.open('POST', 'http://yoursite.com/aspwebservice');
// you may have to change the content type depending on your service
// but this is the correct type for binary data
postDataTOServer.setRequestHeader("Content-Type", "application/octet-stream");
// This does a POST to server
postDataTOServer.send(data);