AngularJS Cross domain POST request blocked CORS

I am working on an application that uses an API from another domain that has no control over its title.

The API allows you to publish an api to it by passing it the username and key in the url. The method should be post and the code would like something like this.

$http({
url : url,
method : "POST",
headers : {
     'Content-Type' : 'application/json'
 },
 data : {
     name: "joe", number: 1234567890
 }
}).success(function(data) {
   //do something
});

      

the sent data passes as an object as above.

I'm new to CORS, but I have a concept idea. Again I have to access the API. The instructions say that I need to submit a post request and pass the "Content-Type": "application / json" content type header

Any help is appreciated, I looked at the post about changing angular options in config mode

$httpProvider.defaults.withCredentials = true;
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];

      

But he doesn't do anything. I believe this was a fix for an older version of Angular. Other solutions require access to a server which I don't have. The header response looks something like this:

Allow   GET,PUT,POST,PATCH,HEAD,OPTIONS
Content-Encoding    gzip
Content-Type    text/html; charset=utf-8
Date    Wed, 15 Oct 2014 06:42:43 GMT
P3P policyref="https://www.somedomaincom/w3c/p3p.xml", CP="NON DSP COR CURa ADMa DEVa PSAa PSDa IVAa IVDa CONa TELa OUR STP PHY ONL COM NAV INT DEM CNT PRE"
Server  nginx/1.1.19
Transfer-Encoding   chunked
Vary    Host, Cookie

      

+3


source to share





All Articles