使用 vue.js 的 get⼀post请求错误出现以下字样,怎么解决?

2025-05-11 04:41:49
推荐回答(1个)
回答1:

解决方法如下:

  • 完整的代码如下(遇到类型问题的同学可以做个参考):

  • 复制代码 代码如下:

  • var querystring = require('querystring')

, http = require('http');

var data = querystring.stringify({

info:'hi',

test:5

});

var opt = {

hostname:'www.test.com',

port :9094,

path:'/perationSqlQuery',

method: 'POST',

headers: {   

'Content-Type':'application/x-www-form-urlencoded',

'Content-Length': data.length  

};

var req = http.request(opt, function (res) {  

res.on('data', function (data) {

console.log(data.toString());

});

});

req.on('error', function(e) {

console.log('problem with request: ' + e.message);

});

req.write(data);

req.end();