3
是否可以将“ArrayBuffer”转换为JSON等“可读”格式?是否有可能将“ArrayBuffer”转换为JSON等“可读”格式? - Chrome扩展
测试脚本:在背景
<script>
try {
http = new ActiveXObject("Microsoft.XMLHTTP"); // Trying IE
}
catch(e) // Failed, use standard object
{
http = new XMLHttpRequest();
}
var url = "http://localhost/test.htm";
var params = "param=abc¶m2=62";
http.open("POST", url, true);
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert('send..');
}
}
http.send(params);
</script>
(Chrome扩展)请求收听: (接收来自TEST.HTM XHR)
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
console.log(details);
},
{
urls: ["*://localhost/*"]
},
['requestBody']);
的console.log结果:
Object {frameId: 0, method: "POST", parentFrameId: -1, requestBody: Object, requestId: "12981"…}
frameId: 0
method: "POST"
parentFrameId: -1
requestBody: Object
raw: Array[1]
0: Object
bytes: ArrayBuffer
byteLength: 32
__proto__: ArrayBuffer
constructor: function ArrayBuffer() { [native code] }
slice: function slice() { [native code] }
__proto__: Object
__proto__: Object
length: 1
__proto__: Array[0]
__proto__: Object
requestId: "12981"
tabId: 180
timeStamp: 1367604574726.125
type: "xmlhttprequest"
url: "http://localhost/test.htm"
__proto__: Object
我需要将details.requestBody.raw重新转换为param = abc & param2 = 62或JSON。 谢谢
http://developer.chrome.com/dev/extensions/webRequest.html
的可能重复[Chrome扩展:如何从内容脚本而不会失去它的类型背景通过ArrayBuffer或斑点?( http://stackoverflow.com/questions/8593896/chrome-extension-how-to-pass-arraybuffer-or-blob-from-content-script-to-the-bac) – 2013-05-03 19:25:10
有没有解决这个问题? – K2xL 2014-01-18 16:57:40