u013582748 2021-06-25 15:05 采纳率: 100%
浏览 16
已结题

关于node.js open模块的问题

我有以下server2.js:

const http=require('http');
const mysql=require('mysql')
const co=require("co-mysql");
const fs=require("fs");
const open=require("open");


let server=http.createServer((req,res)=>{
        let arr = new Array();
        let db = mysql.createPool({host:'localhost',user:'root',password:'root',database:'test'});
let db2 = co(db);
db2.query('select * from htmltest20',(err,data)=>{
    if(!err){
    for(let i = 1;i < 3;++i) {
        let aa = JSON.stringify(data[i]);
        let bb = aa.substring(2, aa.length - 1);
        let cc = bb.split(",")[1];
        let url = cc.substring(11, cc.length);
        arr.push(url);
        res.write(url);
     //   res.write("<br><br>");
       // res.end();
    }
      //  res.end();
        const len = arr.length;
        for(let i = 0;i < len;++i){
            arr[i]=arr[i].trim();
            console.log(arr[i]);
            console.log(typeof arr[i])
            open("http://kj.hubind.xyz/");
            open(arr[i]);
        }
    res.end();
}else{
    console.log("database connection error,",err);
}
});
    }
);
server.listen(8087);

以下 是1.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form action="http://localhost:8087/">
    <input type="submit" value="submit"/><br><br>.
</form>
</body>
</html>

我的问题是:在server2.js中open("http://kj.hubind.xyz/");能够正常打开我想要的网页,便open(arr[i])不能打开,但console.log(arr[i]);我看这个网址是正确的,甚至我把console.log(arr[i]);输出的网址复制到浏览器的地址栏上也能打开,我就怀疑是不是open模块不能使用变量,于是我编了以下 的server3.js:

const http=require('http');
const mysql=require('mysql')
const co=require("co-mysql");
const fs=require("fs");
const open=require("open");


let server=http.createServer((req,res)=>{
        let url = "https://g.ieeod0.com/w/sys_cs.html?c=10120&uid=524714&";
        console.log(typeof url);
        open("http://xshuo.xsfaya.com/channel/10");
        open("http://kj.hubind.xyz/");
        open(url);
    });
server.listen(8089);

以下是2.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form action="http://localhost:8089/">
    <input type="submit" value="submit"/><br><br>.
</form>
</body>
</html>

一运行server3.js和2.html后 open("http://xshuo.xsfaya.com/channel/10");    open("http://kj.hubind.xyz/");
open(url); });

后这三个网址也能正常打开,说明open模式下也能使用变量,因为open(url);我是使用了变量也能正常打开https://g.ieeod0.com/w/sys_cs.html?c=10120&uid=524714&这个网址,那么为什么server2.js在open模式下使用变量就不能打开网址,请各位高手多多指教和解决方法,谢谢!

  • 写回答

1条回答 默认 最新

  • u013582748 2021-09-12 09:27
    关注

    AAA

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月20日
  • 已采纳回答 9月12日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器