「ArrayBuffer」を JSON のような「読み取り可能な」形式に変換することは可能ですか?
テスト スクリプト:
<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>
Background (chrome 拡張機能) Request LISTENER: (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¶m2=62 または JSON に戻す必要があります。ありがとうございました