node.js请求 - 邮政

问题描述 投票:0回答:2
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主机:
node.js
2个回答
4
投票
https://localhost:8080/v1beta1/text:synthesize?key=API_KEY

明显地,您将无法看到响应,但是整个原始请求数据都可以供您在终端中进行检查。

This is documented

here
:

至少有三种调试请求操作的方法:

-1
投票

启动节点过程,例如NODE_DEBUG=request node script.js

lib

request
  1. otherlib

    也可以工作)。

    SET
    require('request').debug = true
    随时随地(这与#1相同)。
    使用
    request-debug
    模块查看请求和响应标头和尸体。

  2. indodejs

  3. 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');
  4. 
    
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.