【问题标题】:how to send a post request through http in website that uses https?如何在使用 https 的网站中通过 http 发送 post 请求?
【发布时间】:2021-02-28 20:42:47
【问题描述】:

我正在创建一个 chrome 扩展程序,它需要通过普通 http 向服务器发送 post 请求,但这会导致混合内容错误,并且当我在用户 Https 的网站中时浏览器不会处理该请求。

错误信息:

混合内容:“https://www.google.com/”页面通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点“http://example.se:8080/v1/check”。此请求已被阻止;内容必须通过 HTTPS 提供。

    var settings = {
  "url": "http://example.se:8080/v1/check",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "postman-token": "e7705111-e7d7-0284-e4cd-56115243e076",
    "Content-Type": "application/json"
  },
  "data": JSON.stringify({"langCode":"pt-rr","text":"Por favor, leia as regrs. Meu nom é Nicolas. bowré o qunto maor pabn dks do."}),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

【问题讨论】:

  • 为什么需要通过 HTTP 发送?您有权访问网络服务器吗?升级到 HTTPS 确实是这里的解决方案。
  • 我无法访问服务器,这就是为什么我试图找到解决办法

标签: javascript ajax google-chrome-extension https xmlhttprequest


【解决方案1】:

不推荐使用mix-content,你应该使用HTTPS

但如果您想出于开发目的绕过它,您可以在网站设置中允许它。

参考这个问题 How to get Chrome to allow mixed content?

【讨论】:

    猜你喜欢
    • 2020-06-13
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多