在节点JS请求中发送未parsing的数据
我想发送一个POST请求(例如,与'请求'模块),但我没有find一种方式发送未分析的数据* 。
* unparsed data =>直接从Chrome开发工具中复制。 例如: tipo_accion = 3&filtro = descarga&fecha = actual
它也会把这个string翻译成JSON。
我已经尝试过…
var request = require('request'); request.post({ url: 'https://target.com/form/', form: 'tipo_accion=3&filtro=descarga&fecha=actual' }, function (error, response, body) { console.log(body) } );
…但它没有工作。
首先您应该了解请求方法post
和get
之间的区别。
你想发送的结构: tipo_accion=3&filtro=descarga&fecha=actual
告诉我你想要使用get
请求。 所以适当的代码将是这样的:
request( 'https://target.com/form/&tipo_accion=3&filtro=descarga&fecha=actual', function (error, response, body) { console.log(body) }, );
但是,如果这是一个post
请求,那么你应该使用json格式
request.post({ url: 'https://target.com/form/', form: { tipo_accion: 3, filtro: 'descarga', fecha: 'actual' }, function(error, response, body) { console.log(body) } );