NodeJS 如何修复错误:选项.uri是一个必需的参数?

qco9c6ql  于 2023-11-17  发布在  Node.js
关注(0)|答案(1)|浏览(124)

我试图发出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);

字符串

kqlmhetl

kqlmhetl1#

错误:选项.uri是必需的参数
如果您提供的URL被证明是一个假值,则可能会出现此错误。

// 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

您可以记录URL并检查值

相关问题