AngularJS: POST request payload empty for ArrayBuffer -
i tried use post send bytes using arraybuffer
, seems request payload empty. here's code snippet:
var buffer = new arraybuffer(10); var dataview = new dataview(buffer); dataview.setint32(0, 0x1234abcd); var request = { method: 'post', url: 'url', headers: {'content-type': 'application/octet-stream'}, data: buffer, responsetype: 'arraybuffer' }; $http(request) .success(function(data, status, headers, config) { ... }) .error(function(data, status, headers, config) { ... });
as commented, send arraybuffer, need use xhr2 directly (seems angularjs doesn't support it). here's code of how it:
var buffer = new arraybuffer(10); var dataview = new dataview(buffer); dataview.setint32(0, 0x1234abcd); var xhr = new xmlhttprequest(); xhr.open('post', 'url', true); xhr.onload = function(e) { console.log('data received'); }; xhr.send(buffer);
more details xhr2: http://www.html5rocks.com/en/tutorials/file/xhr2/#toc-send-string, hope who's puzzled :)
Comments
Post a Comment