Yar*_*veh 4 javascript v8 embedded-v8
我想用JavaScript引擎独立的,如我将在命令行中运行它解释了V8 在这里:
$> ./v8-shell -e 'print("10*10 = " + 10*10)'
Run Code Online (Sandbox Code Playgroud)
我希望javascript执行一些http请求,最好使用jQuery API,但XMLHttpRequest也可以.
V8中是否有内置方法来执行此操作?如果没有实现访问者/ cpp扩展,有没有办法实现它?
V8中是否有内置方法来执行此操作?
不是直接在V8中,但NodeJS增加了网络和文件系统功能,以及其他功能.
从文档中窃取一个例子:
var options = {
host: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
};
var req = http.request(options, function(res) {
// callback invoked when response is received
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
// 'data' event is fired whenever a chunk of the response arrives
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.end();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3355 次 |
| 最近记录: |