GVKun编程网logo

如何将 router.get 和 https.get 一起使用? 节点.js(route::get)

3

如果您对如何将router.get和https.get一起使用?节点.js感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何将router.get和https.get一起使

如果您对如何将 router.get 和 https.get 一起使用? 节点.js感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何将 router.get 和 https.get 一起使用? 节点.js的详细内容,我们还将为您解答route::get的相关问题,并且为您提供关于./node_modules/react-router-dom/react-router-dom.js尝试导入错误:未从“ react-router”导出“ Navigate”、404 GET https://example.com/__tryOrUnsub@https://example.com/main-es2015.js.map、aiohttp,在 GET 上引发错误,无法向 https 网站发送 GET 请求、angular-infinite-list 地址:https://github.com/a-jie/angular-infinite-list例子:如何将 router.get 和 https.get 一起使用? 节点.js(route::get)

  • ./node_modules/react-router-dom/react-router-dom.js尝试导入错误:未从“ react-router”导出“ Navigate”
  • 404 GET https://example.com/__tryOrUnsub@https://example.com/main-es2015.js.map
  • aiohttp,在 GET 上引发错误,无法向 https 网站发送 GET 请求
  • https://github.com/a-jie/angular-infinite-list例子:angular-infinite-list 地址:https://github.com/a-jie/angular-infinite-list例子:如何将 router.get 和 https.get 一起使用? 节点.js(route::get)

    如何将 router.get 和 https.get 一起使用? 节点.js(route::get)

    如何解决如何将 router.get 和 https.get 一起使用? 节点.js

    我想从 http 请求中获取信息并通过路径“/get”将其发送到前端。我结合了这 2 个函数,它可以工作,但我认为它不正确:

    1. const router = express.Router();
    2. const https = require(''https'');
    3. router.get(''/get'',(req,res) => {
    4. https.get(''https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY'',(resp) => {
    5. let data = '''';
    6. resp.on(''data'',(chunk) => {
    7. data += chunk;
    8. });
    9. resp.on(''end'',() => {
    10. res.json(JSON.parse(data).explanation)
    11. });
    12. }).on("error",(err) => {
    13. console.log("Error: " + err.message);
    14. });
    15. });

    有没有更好的方法来做到这一点?

    解决方法

    不,它工作正常。

    但如果你想要另一种方式,那么使用 axios

    您需要要求 axios,然后在路由器中添加您的请求。

    1. const axios = require(''axios'');
    2. // Make a request for a user with a given ID
    3. axios.get(''/user?ID=12345'')
    4. .then(function (response) {
    5. // handle success
    6. console.log(response);
    7. })
    8. .catch(function (error) {
    9. // handle error
    10. console.log(error);
    11. })
    12. .then(function () {
    13. // always executed
    14. });

    您可以从 here

    获得更多信息 ,

    更好的方法是使用 Axios 将所有 http 请求发送到您想要从 nodejs 应用程序发送的外部 api。它是一个基于承诺的请求库,您可以在浏览器和后端服务器中使用。

    1. 使用 npm install axios
    2. 安装 axios
    3. axios.get(''https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY'').then(response => res.send(response.data)).catch(error => console.log(error));
  • ./node_modules/react-router-dom/react-router-dom.js尝试导入错误:未从“ react-router”导出“ Navigate”

    如何解决./node_modules/react-router-dom/react-router-dom.js尝试导入错误:未从“ react-router”导出“ Navigate”

    ./node_modules/react-router-dom/react-router-dom.js Attempted import error: ''Navigate'' is not exported from ''react-router''.

    react-router-dom的版本是6.0.0-alpha.2,而react-router是5.2.0。 两者均已正确安装。我不确定如何解决此错误。有人可以给我任何可能的解决方法吗?

    我的代码中甚至没有<Navigate to=?>行。

    解决方法

    为什么只安装两个都需要,这可以工作

    1. 执行npm删除react-router
    2. 删除node_modules
    3. 纱线安装或npm安装和
    4. 启动纱线或启动npm

    404 GET https://example.com/__tryOrUnsub@https://example.com/main-es2015.js.map

    404 GET https://example.com/__tryOrUnsub@https://example.com/main-es2015.js.map

    如何解决404 GET https://example.com/__tryOrUnsub@https://example.com/main-es2015.js.map

    自从更新到 NG 11 后,我在浏览器控制台中看到奇怪的 404 错误,例如:

    1. 404 GET https://example.com/__tryOrUnsub@https://example.com/main-es2015.js.map
    2. 404 GET https://example.com/Me@https://example.com/main-es2015.js.map

    和其他人。

    我看不出这些可能来自我的代码中的哪里。

    还有人看到这个吗?

    enter image description here

    谢谢

    aiohttp,在 GET 上引发错误,无法向 https 网站发送 GET 请求

    aiohttp,在 GET 上引发错误,无法向 https 网站发送 GET 请求

    如何解决aiohttp,在 GET 上引发错误,无法向 https 网站发送 GET 请求

    我有这个发送 GET 请求的代码部分:

    1. proxy_auth = aiohttp.BasicAuth(''proxy-username'',''proxy-password'')
    2. async with session.get(''https://google.com'',headers=headers,proxy=''http://proxy_url.com'',proxy_auth=proxy_auth) as response:
    3. html = await response.text()

    问题是当我尝试 GET https 网站时,它返回此异常:

    1. ClientConnectorError: Cannot connect to host google.com:443 ssl:default [The parameter is incorrect]

    仅当网站由 https 提供时才会抛出此异常,而 http 则没有异常。 代理是 https 但 aiohttp 只接受 http 代理,但我知道有一些技巧可以让它工作。

    解决方法

    我找到了解决该问题的方法。这是因为 aiohttp 库本身,所以我们需要将 Event Policy Loop 更改为 asyncio.WindowsSelectorEventLoopPolicy()

    像这样:

    1. import asyncio
    2. asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

    https://github.com/a-jie/angular-infinite-list例子:https://github.com/a-jie/angular-infinite-list例子:

    https://github.com/a-jie/angular-infinite-list例子:angular-infinite-list 地址:https://github.com/a-jie/angular-infinite-list例子:

    Using npm:

    npm install angular-infinite-list --save
    

    Import angular Infinite list module into your app module

    import { InfiniteListModule } from ''angular-infinite-list'';
    
    @NgModule({
      imports: [
        browserModule,
        FormsModule,
        InfiniteListModule,
        ...
    

    Wrap Infinite list tag around list items

    <infinitelist
        [width]=''"100%"'' 
        [height]=''500'' 
        [data]=''data'' 
        [itemSize]=''50'' 
        (update)=''event = $event''>
            <div *ngFor="let item of event?.items; let i=index;" [ngStyle]="event.getStyle(i)">
                item{{event.start + i}} : {{item|json}}
            </div>
    </infinitelist>
    
    or directive usage
    <div infinitelist [width]=''"100%"'' ...</div>
    

    angular-infinite-list 地址:<a href="https://github.com/a-jie/angular-infinite-list">https://github.com/a-jie/angular-infinite-list</a>例子:<a href="https://a-jie.github.io/angular-infinite-l 官网

    https://github.com/a-jie/angular-infinite-list例子:https://github.com/a-jie/angular-infinite-list

    今天关于如何将 router.get 和 https.get 一起使用? 节点.jsroute::get的分享就到这里,希望大家有所收获,若想了解更多关于./node_modules/react-router-dom/react-router-dom.js尝试导入错误:未从“ react-router”导出“ Navigate”、404 GET https://example.com/__tryOrUnsub@https://example.com/main-es2015.js.map、aiohttp,在 GET 上引发错误,无法向 https 网站发送 GET 请求、angular-infinite-list 地址:https://github.com/a-jie/angular-infinite-list例子:

    本文标签: