ONOS rest api配置来处理cors错误



我正在使用reactjs来显示ONOS数据。但我在获取onos rest api url时遇到了CORS错误。如何配置rest api来克服这个问题。我没有找到任何文件。请跟我来。提前谢谢。

如果你读过Onos的源代码,你会发现Onos避免了CORS错误。但我最近还是遇到了同样的问题,ajax无法通过rest api加载数据。我只是在控制器中用php代替它。这里有一个例子:

public function index() { 
$url = 'your rest api';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, 'username:password');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($curl);
$resultStatus = curl_getinfo($curl);
if($resultStatus['http_code'] == 200) {
echo $response;
} else {
echo 'Call Failed';
}
}

希望能有所帮助。

最新更新