简体   繁体   English

React - 不支持协议“https:”。 预期的“http:”

[英]React - Protocol "https:" not supported. Expected "http:"

Yeah, I saw this post , however I do not have such file where I can edit to use https and my backend is ASP.NET MVC Core 3.1.是的, 我看到了这篇文章,但是我没有可以编辑以使用https的文件,我的后端是 ASP.NET MVC Core 3.1。

So when my React application sends API calls to ASP.NET MVC application, then it throws an error:因此,当我的 React 应用程序向 ASP.NET MVC 应用程序发送 API 调用时,它会抛出一个错误:

TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
    at new NodeError (node:internal/errors:371:5)
    at new ClientRequest (node:_http_client:158:11)
    at Object.request (node:https:353:10)
    at Array.stream (C:\My Files\\Scripts\react\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:126:74)
    at ProxyServer.<anonymous> (C:\My Files\\Scripts\react\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at middleware (C:\My Files\\Scripts\react\node_modules\http-proxy-middleware\lib\index.js:46:13)
    at handle (C:\My Files\\Scripts\react\node_modules\webpack-dev-server\lib\Server.js:322:18)
    at C:\My Files\\Scripts\react\node_modules\webpack-dev-server\lib\Server.js:330:47
    at Layer.handle_error (C:\My Files\\Scripts\react\node_modules\express\lib\router\layer.js:71:5)
    at trim_prefix (C:\My Files\\Scripts\react\node_modules\express\lib\router\index.js:315:13)

the url looks like this: url 看起来像这样:

http://localhost:3030/api/foo/bar

Our development config file dev.js looks like this:我们的开发配置文件dev.js如下所示:

// development config
const package = require('../../package.json')
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const commonConfig = require('./common')
const agent = require('agentkeepalive')

module.exports = (webpackConfigEnv, argv) => {
    return merge(commonConfig(argv), {
        mode: 'development',
        entry: [
            'react-hot-loader/patch', // activate HMR for React
            'webpack-dev-server/client?http://localhost:3030', // 
            'webpack/hot/only-dev-server', // bundle the client for hot reloading
            './index.tsx', // the entry point of our app
        ],
        devServer: {
            port: 3030,
            hot: true, // enable HMR on the server
            historyApiFallback: true, //
            proxy: {
                '/api/*': {
                    target: argv.env.mock ? '' : 'https://localhost:43000',
                    secure: false,
                    changeOrigin: true,
                    agent: new agent({
                        maxSockets: 100,
                        keepAlive: true,
                        maxFreeSockets: 10,
                        keepAliveMsecs: 100000,
                        timeout: 6000000,
                        freeSocketTimeout: 90000, // free socket keepalive for 90 seconds
                    }),
                    onProxyRes: (proxyRes) => {
                        var key = 'www-authenticate'
                        proxyRes.headers[key] =
                            proxyRes.headers[key] && proxyRes.headers[key].split(',')
                    },
                },
            },
        },
        devtool: 'cheap-module-source-map',
        plugins: [
            new webpack.HotModuleReplacementPlugin(), // enable HMR globally
            new webpack.DefinePlugin({
                'process.env.appVersion': JSON.stringify(package.version),
                'process.env.isMockMode': JSON.stringify(argv?.env?.mock),
                'process.env.isDevelopment': true,
            }),
        ],
    })
}

How can I solve this issue?我该如何解决这个问题? I cannot use http://localhost:43000 because my backend uses SSL. Ahy help would be greatly appreciated!我不能使用http://localhost:43000 ,因为我的后端使用 SSL。非常感谢您的帮助!

Protocol "https:" not supported.不支持协议“https:”。 Expected "http:"预期的“http:”

The error is thrown by agent .错误由agent抛出。 It is necessary to use https :有必要使用https

agent: new agent.HttpsAgent({
    maxSockets: 100,
    keepAlive: true,
    maxFreeSockets: 10,
    keepAliveMsecs: 100000,
    timeout: 6000000,
    freeSocketTimeout: 90000, // free socket keepalive for 90 seconds
}),

暂无
暂无

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

相关问题 节点 js 错误:不支持协议“https:”。 预期“http:” - Node js Error: Protocol "https:" not supported. Expected "http:" Nodejs 错误:不支持协议“http:”。 预期“https:” - Nodejs Error: Protocol “http:” not supported. Expected “https:” Azure SpeechSynthesizer 错误 HTTP:不支持。 预期的 HTTPS:NPM `microsoft-cognitiveservices-speech-sdk` - Azure SpeechSynthesizer Error HTTP: not supported. Expected HTTPS: NPM `microsoft-cognitiveservices-speech-sdk` 仅协议方案支持React Native WebView Cross起源请求:http,data,chrome,https - React Native WebView Cross origin requests are only supported for protocol schemes: http, data, chrome, https DiscordAPIError:无效的表单正文 embed.image.url:不支持方案“[对象响应]”。 方案必须是 ('http', 'https') 之一 - DiscordAPIError: Invalid Form Body embed.image.url: Scheme “[object response]” is not supported. Scheme must be one of ('http', 'https') 协议HTTP和https不匹配 - Mismatch protocol http and https AngularJS错误:仅支持协议方案的跨源请求:http,数据,chrome扩展,https - AngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https 交叉源请求仅支持协议方案:http,数据,chrome,chrome-extension,https - Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https × 错误:Alchemy URL 协议必须是 http、https、ws 或 wss 之一。 收到:未定义的 React.js - × Error: Alchemy URL protocol must be one of http, https, ws, or wss. Recieved: undefined React.js 在一些链接中找到http协议并转换为https - Find http protocol in some links and convert it to https
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM