简体   繁体   English

无法从 https 向 http 服务器发送 axios 请求

[英]Can't send a axios request from https to http server

The frontend of my project is on the https protocol and the server side is on the http protocol, I cannot send an axios request to the server我的项目前端是https协议,服务端是http协议,无法向服务端发送axios请求

Use MERN stack.使用 MERN 堆栈。 (React on typescript) (对打字稿做出反应)

Axios http.ts Axios http.ts

export const $api = axios.create({
    withCredentials: true,
    baseURL: process.env.REACT_APP_SERVER_URL
})

Axios request function Axios 请求 function

static async CreateOrder(data: IOrder): Promise<AxiosResponse<IOrder>> {
    return $api.post<IOrder>('/test', data)
};

On the localhost all works without errors.在本地主机上,所有工作都没有错误。 But after deploating to the server and domain, I get an error但是在部署到服务器和域之后,我得到一个错误

Mixed Content: The page at 'https://xxxxxxxxxx.netlify.app/place' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://0.00.000.00/test'. This request has been blocked; the content must be served over HTTPS.

Uncaught (in promise) Fo {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}

This request is blocked by chrome, but it is correct to send a request from https to https, but I want to disable this and be able to send to http这个请求被chrome屏蔽了,但是从https发送请求到https是正确的,但是我想禁用这个,能够发送到http

You can't do requests from https to http because it's a security feature to prevent attackers/hackers from intercepting and modifying the insecure HTTP content and this behavior is called as mixed content blocking.你不能做从 https 到 http 的请求,因为它是一种安全功能,可以防止攻击者/黑客拦截和修改不安全的 HTTP 内容,这种行为称为混合内容阻止。 You can read more to understand with more details in this article .您可以在本文中阅读更多内容以了解更多详细信息。

But to help you try these options:但为了帮助您尝试这些选项:

  1. You can avoid it putting your webserver as https instead of http.您可以避免将您的网络服务器设置为 https 而不是 http。
  2. Use ngrok or another service (maybe your own service) to proxy your http server into a https使用ngrok或其他服务(可能是您自己的服务)将您的 http 服务器代理到 https
  3. Disable mixed content blocking from your browser从浏览器禁用混合内容阻止

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM