Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过客户端站点上的api获取https内容,但浏览器会引发混合内容http错误_Javascript_Django_Fetch Api_Mixed Content - Fatal编程技术网

Javascript 通过客户端站点上的api获取https内容,但浏览器会引发混合内容http错误

Javascript 通过客户端站点上的api获取https内容,但浏览器会引发混合内容http错误,javascript,django,fetch-api,mixed-content,Javascript,Django,Fetch Api,Mixed Content,我正试图在Django应用程序中构建一个外部API,将一些内容提供给生产客户端Wordpress站点。客户端使用https,javascript使用fetch获取https api url,但浏览器声称http混合内容。有什么好处 我试过Chrome和Firefox,都返回了类似的错误 fetch('https://mysite.pythonanywhere.com/apit?param1=100000&param2=1000', { method: 'GET', })

我正试图在Django应用程序中构建一个外部API,将一些内容提供给生产客户端Wordpress站点。客户端使用https,javascript使用fetch获取https api url,但浏览器声称http混合内容。有什么好处

我试过Chrome和Firefox,都返回了类似的错误

fetch('https://mysite.pythonanywhere.com/apit?param1=100000&param2=1000', {
    method: 'GET',
  })
  .then(function(response) {
    if (response.status !== 200) {
      console.log(response);
      console.log('Looks like there was a problem. Status Code: ' +
        response.status);
      return;
    }
  });
我在Django对此的看法如下:

response = JsonResponse(the_content_dict,safe=False)
return response
我可以直接在浏览器中访问URL,并按预期查看json响应,但当我将上面的代码放在客户端WP站点上时,我会在Firefox控制台中看到:

Blocked loading mixed active content “http://mysite.pythonanywhere.com/apit?param1=100000&param2=1000”

TypeError: NetworkError when attempting to fetch resource. rank:154:3
Response { type: "cors", url: "https://mysite.pythonanywhere.com/apit?param1=100000&param2=1000", redirected: false, status: 500, ok: false, statusText: "Internal Server Error", headers: Headers, body: ReadableStream, bodyUsed: false }
Looks like there was a problem. Status Code: 500
同样,在Chrome中:

(index):154 Mixed Content: The page at 'https://clientsite.com' was loaded over HTTPS, but requested an insecure resource 'http://mysite.pythonanywhere.com/apit?param1=100000&param2=1000'. This request has been blocked; the content must be served over HTTPS.
(anonymous) @ (index):154
(index):1 Uncaught (in promise) TypeError: Failed to fetch

为什么浏览器试图在获取中加载非https版本而不是https?我正在使用django cors Header将似乎正在工作的客户端域列入白名单。

您的代码中是否有某种类型的重定向,将其重定向到不安全的资源。这显然不是一个CORS问题:它与访问http vs HttpSincidentially有关,似乎您有一个比混合内容问题更大的问题:控制台消息显示响应是一个500内部服务器错误……您的代码中是否有某种类型的重定向,将其重定向到不安全的资源。这显然不是一个CORS问题:它与访问http vs HttpS有关,似乎您有一个比混合内容问题更大的问题:控制台消息显示响应是一个500内部服务器错误…