1

我正在制作一个应用程序,我想将 $http.get 请求发送到 duckduckgo 的 API,但他们的请求是通过 HTTP 完成的。看到我的网站是 HTTP 得到以下错误:

angular.js:11756 Mixed Content: 
The page at 'URL' was loaded over HTTPS, 
but requested an insecure XMLHttpRequest endpoint 'http://api.duckduckgo.com/'. 
This request has been blocked; the content must be served over HTTPS.

当我将 s 添加到我的请求中时,我显然得到以下信息(看到未设置 CORS):

XMLHttpRequest cannot load:
https://api.duckduckgo.com/?q=Undulated%20Tinamou&format=json&pretty=1. 
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'https://URL' is therefore not allowed access. The response had HTTP status code 405.

我的问题:我是否可以获取 json 并绕过上述两种方法之一?

编辑1:

$http.get('https://api.duckduckgo.com/?q=' + birdname + '&format=json&callback=jsonp&pretty=1').then(function(res){
            console.log(res.data);
        });

我还尝试了以下方法:

$http.jsonp('https://api.duckduckgo.com/?q=' + birdname + '&format=json&callback=jsonp&pretty=1').then(function(res){
                console.log(res.data);
            });

第二个,我收到以下错误:

Uncaught ReferenceError: json is not defined
4

0 回答 0