1

I am using reactjs to show ONOS data. But I am getting CORS error when fetching onos rest api url. How to configure rest api to overcome this problem. I did not find any documentation. Please helo me. Thanks in advance.

1 Answers1

0

You would find Onos had avoided CORS error, if you ever read Onos's source code. But I still met the same problem recently, ajax couldn't fatch the data through rest api. I just did it in controller with php instead. Here is an example:

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';
    }
}

Hope it helps.