SSL authentication

Asked

Viewed 129 times

1

I am facing a small problem with an api, whenever I send the request I get the following errors:

jquery-3.3.1.min. js:2 Failed to load https://api.iugu.com/v1/invoices: Response to preflight request doesn’t pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'https://hstc.com.br' is therefore not allowed access. send @jquery-3.3.1.min. js:2 [email protected]. js:2 (Anonymous) @ (index):14 (index): 1 Failed to load https://api.iugu.com/v1/invoices: No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'https://hstc.com.br' is therefore not allowed access. The Response had HTTP status code 401.

I’m using this code to access:

<!doctype html>
  <html>
          <header>

          </header>
          <head>
                    <script src="jquery-3.3.1.min.js"></script>

                  <script type="text/javascript">



                                   $.ajax
                                            ({
                                            type: "POST",
                                            url: "https://api.iugu.com/v1/invoices",
                                            dataType: 'json',
                                            crossDomain: true,
                                            async: false,
                                            headers: {
                                            "Authorization": "Basic " + btoa("xxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ":"),
                                            "Access-Control-Allow-Origin":"*",
                                            "Access-Control-Allow-Methods": "HEAD, GET, POST, PUT, PATCH, DELETE",
                                            "Access-Control-Allow-Headers":"Origin, Content-Type, X-Auth-Token"
                                            },
                                            data: '{ "comment" }',
                                            success: function (){
                                            alert('Thanks for your comment!'); 
                                            }
                                            });


                                    var data = JSON.stringify({
                                    "email": "[email protected]",
                                    "due_date": "2018-10-08",
                                    "items": [
                                    {
                                    "description": "carro",
                                    "quantity": 1,
                                    "price_cents": 1500000
                                    }
                                    ],
                                    "payer": {
                                    "cpf_cnpj": "xxxxxxxxxxx",
                                    "phone_prefix": "31",
                                    "phone": "xxxxxxxx",
                                    "address": {
                                    "zip_code": "3xxxxxxx",
                                    "number": "109"
                                    }
                                    }
                                    });

                                    var xhr = new XMLHttpRequest();
                                    xhr.withCredentials = true;

                                    xhr.addEventListener("readystatechange", function () {
                                    if (this.readyState === this.DONE) {
                                    console.log(this.responseText);
                                    }
                                    });

                                    xhr.open("POST", "https://api.iugu.com/v1/invoices");

                                    xhr.send(data);

                  </script>
          </head>
          <body>

          </body>
  </html>

Cv with some company colleagues said it might be due to SSL, someone knows how to disable it?

  • https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.