简体   繁体   English

本地执行 Google:https 请求失败

[英]Local Execution Google: https request failed

Goal目标

Ensure security in my request message.确保我的请求消息中的安全性。

Environment:环境:

Library: Version图书馆:版本

  • node-fetch : 2.6.0节点获取: 2.6.0

  • https : natively implemented in node, it seems https : 在 node 中本地实现,似乎

  • node : 12.15.0节点:12.15.0

Device : Version设备:版本

  • Google home nest mini : 2nd generation Google Home Nest mini : 第二代

Issue问题

I get a "Failed to fetch" error when I do get request on an api served with https and self certified certificate.当我在使用 https 和自认证证书提供的 api 上收到请求时,我收到“无法获取”错误。

What I tried:我试过的:

1 - http request: it works fine on google home device and my local machine, 1 - http 请求:它在 google home 设备和我的本地机器上工作正常,

2 - https request: it works on my local machine but not on google home device. 2 - https 请求:它适用于我的本地机器,但不适用于 google home 设备。

Code I use:我使用的代码:

import fetch from 'node-fetch';
import env from './configFile';
import https, { Agent } from 'https';

export default function get(): Promise<any> {
    const url = "https://api.url"; 
    const httpsAgent = new https.Agent({
        rejectUnauthorized: false,
    });

    const option = {
        method: 'get',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
            Authorization: 'Basic ' + btoa(env.login! + ':' + env.password!),
        },
        agent: httpsAgent,
    };

    return fetch(url, option)
        .then(res => {
            return res.json();
        })
        .catch(error => {
            throw new Error(error);
        });
}

Here I disable ssl certification verification.这里我禁用ssl认证验证。 It is something i'll change later because it is not secure, but at least i want to do an https request without error.这是我稍后会更改的内容,因为它不安全,但至少我想做一个 https 请求而不会出错。

My Errors我的错误

Go to this link: errors转到此链接: 错误

Reproduce Error重现错误

I made a full tutorial, if you want to reproduce the error: https://github.com/killvi/localExecutionHttpsError我做了一个完整的教程,如果你想重现错误: https : //github.com/killvi/localExecutionHttpsError

In this tuto, i try to make an https request on google to check if I can do it without error.在本教程中,我尝试在 google 上发出 https 请求,以检查我是否可以做到没有错误。 So is not exactly same implementation as mine.所以与我的实现并不完全相同。 But if it works with google, at least i will known that my problem does not come from https implementation in google home device.但如果它适用于谷歌,至少我会知道我的问题不是来自谷歌家庭设备中的 https 实现。

Google answered my question:谷歌回答了我的问题:

Currently, local execution apps can only use unencrypted HTTP/TCP/UDP to communicate locally to their devices.目前,本地执行应用程序只能使用未加密的 HTTP/TCP/UDP 与其设备进行本地通信。 It has been requested that we enable TLS capabilities over the local channel to enable HTTPS and other standard encrypted transport methods.已要求我们通过本地通道启用 TLS 功能,以启用 HTTPS 和其他标准加密传输方法。

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

相关问题 https://docs.google.com 的请求失败返回代码 400。截断的服务器响应: - Request failed for https://docs.google.com returned code 400. Truncated server response: Google脚本:https:// www…的请求失败,返回了代码416。服务器被截断 - Google Script: Request failed for https://www… returned code 416. Truncated server 对 https://docs.google.com 的请求失败,返回代码 401 - 保存并通过电子邮件发送来自 Google 表格的 PDF 文件 - Request failed for https://docs.google.com returned code 401 - saving and emailing PDF files from Google Sheets Https Nginx NodeJS SocketIO和CORS请求失败 - Https Nginx NodeJS SocketIO And CORS request failed Google Chrome扩展程序HTTPS Ajax请求 - Google Chrome Extension HTTPS Ajax Request AJAX Https 请求显示 CORS 错误。 (来自本地服务器) - AJAX Https request showing CORS error. (From local server) EINVRES请求https://bower.herokuapp.com/packages/失败,502 - EINVRES Request to https://bower.herokuapp.com/packages/ failed with 502 对https://registry.npmjs.org/yargs的请求失败 - request to https://registry.npmjs.org/yargs failed React Native fetch https localhost网络请求失败 - React Native fetch https localhost network request failed 发送 http 请求 api 不安全/不是 https 在生产中失败 - Send http request for api that not secure / not https in NEXTJS failed in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM