我正在尝试发出CORS POST请求,但它发出此错误:
错误:options.uri是必需参数
这是我的代码:
var express = require('express');
var request = require('request');
var app = express();
var gg = false;
var gg2 = false;
app.use('/', function(req, res, next) {
var url = req.url.substr(1);
req.headers = {};
req.headers['Host'] = "*";
req.header['Cache-Control'] = 'no-cache';
req.header['User-Agent'] = 'iPad\r\n';
req.header['Accept'] = '*/*';
req.header['Accept-Encoding'] = 'gzip, deflate, sdch, br';
req.header['Accept-Language'] = 'en-US,en;q=0.8';
res.header('access-control-allow-origin', '*');
// console.log(url);
var proxy = request(url);
proxy.on('data', function(data) {
gg = data;
gg2 = url;
console.log('Proxy data: url: ' + url + "\n" + data);
});
req.pipe(proxy);
proxy.pipe(res);
});
app.listen(process.env.PORT || 8080);

答案 0 :(得分:0)
错误:options.uri是必需参数
如果您提供的网址结果为虚假值,则可能出现此错误。
// A URI is needed by this point, emit error if we haven't been able to get one
if (!self.uri) {
return self.emit('error', new Error('options.uri is a required argument'))
}
源代码:link
您可以记录网址并检查值