const request = require('request');
const headers = {headers: {'input': {'text':'I want to say this'}, 'voice':{ 'languageCode' : 'en-US'},'audioConfig':{'audioEncoding': 'MP3'}}}
request.post('https://texttospeech.googleapis.com/v1beta1/text:synthesize?key=API_KEY',headers, (error, res, body) => {
if (error) {
console.error(error)
return
}
console.log(`statusCode: ${res.statusCode}`)
console.log(body)
})
简单的方法是在任何端口上启动NetCat服务器:
$ nc -l -p 8080
将URL更改为local主机:
https://localhost:8080/v1beta1/text:synthesize?key=API_KEY
明显地,您将无法看到响应,但是整个原始请求数据都可以供您在终端中进行检查。
This is documented
here:
至少有三种调试请求操作的方法:
启动节点过程,例如NODE_DEBUG=request node script.js
lib
,
request
,
otherlib
也可以工作)。
SET随时随地(这与#1相同)。 使用
require('request').debug = true
模块查看请求和响应标头和尸体。
request-debug
indodejs:const http = require('http'); // Create a simple server const server = http.createServer((req, res) => { // Get the relevant data from the request const { rawHeaders, httpVersion, method, socket, url } = req; // Get the relevant data from the WebSocket const { remoteAddress, remoteFamily } = socket; // Prepare the log and response object const data = JSON.stringify({ timestamp: Date.now(), rawHeaders, httpVersion, method, remoteAddress, remoteFamily, url }); // Log the request console.info('---------------'); console.info(data); // Finish the request, and send a response. res.end(data); }); // Start the APP in any port you want server.listen(3000); console.info('App started');