我试图发出CORS POST请求,但它给出了这个错误:
错误:选项.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);
字符串
1条答案
按热度按时间kqlmhetl1#
错误:选项.uri是必需的参数
如果您提供的URL被证明是一个假值,则可能会出现此错误。
字符串
源代码:link
您可以记录URL并检查值