0

I'm trying to use GET from an API(not mine). I test it using simple curl it works normal, but when I try to use axios, axios sends OPTION. Server only accepts GET,HEAD,POST so its throw CORS

Any idea why axios sends OPTION, not GET?

Here's my curl

<?php
$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => 'https://xxxxxx'
]);
$resp = curl_exec($curl);
curl_close($curl);
?>

Here's my axios

export default {
    data: {
        users:[]
    },
      mounted(){
         this.loadData();
      },
  methods:{
     loadData:function(){
        axios.get('https://xxxxxxxx')
        .then(function(response){
            console.log(response.data);
        });  
     }
  }
}

is it problem with the server or i miss something?

Eustia
  • 19
  • 2
  • 2
    You are using cURL from the server side, and the browser is not involved. It is the client browser that enforces cross-origin policy – Andrei Savin May 07 '19 at 17:32
  • Possible duplicate of [XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header](https://stackoverflow.com/questions/35553500/xmlhttprequest-cannot-load-xxx-no-access-control-allow-origin-header) – Quentin Oct 23 '19 at 06:14

2 Answers2

0

In the end, I create an API that fetches data from outside API. Since it works in simple curl, I use that curl in Axios and working. It's not efficient but it's working :)

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
Eustia
  • 19
  • 2
-3

In your laravel press ctrl+p then write Verifycsrftoken and inside
protected $except = [ 'stripe/', enter code here'http://example.com/foo/', //any route ];