我尝试将发布请求发送到API 而且我无法将数据恢复到我的异步函数中, 我已经尝试了下一个代码:
function PostCode(codestring) {
// Build the post string from an object
var post_data = querystring.stringify({
'compilation_level' : 'ADVANCED_OPTIMIZATIONS',
'output_format': 'json',
'output_info': 'compiled_code',
'warning_level' : 'QUIET',
'js_code' : codestring
});
// An object of options to indicate where to post to
var post_options = {
host: 'closure-compiler.appspot.com',
port: '80',
path: '/compile',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(post_data)
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
return chunk;
});
});
// post the data
post_req.write(post_data);
post_req.end();
}
在我的异步函数中,该函数的调用如下所示:
let response = await PostCode(0);
数据在该行上打印良好:
console.log('Response: ' + chunk);
但是退货根本不起作用
我如何安全地将“块”变量返回给我的主要异步函数?
答案 0 :(得分:0)
当您想使用@import "~bootstrap/dist/css/bootstrap.css";
时,您需要返回一个Promise,而Promise需要用您的回复来解决。
await