【问题标题】:How to submit form data through VSCODE?如何通过VSCODE提交表单数据?
【发布时间】:2021-11-28 22:52:13
【问题描述】:

我在通过 VSCODE 提交表单数据时遇到问题。所以基本上我有一个在 vscode 上运行的 nodejs 程序,我的目标是将一些输入数据从该程序提交到一个在线表单。

  1. 在 vscode 中运行 program.js 文件
  2. 文件挑选出用户名字段
  3. 通过php提交到在线文件

这是将输入用户名数据写入 data.txt 的 HTML 文件和 PHP 文件

<!DOCTYPE html>
<html>
<BODY>
<form action = "submit.php" method="POST">
    <p>
        <input type = "text"  name = "username" />
    </p>
    <input type = "submit" name="submit_btn" id = "submit" value = "Submit"/>
    </form>
</BODY>
</html>
<?php
 if(isset($_POST['submit_btn']))
 {
  $username = $_POST['username'];
  $text = $username ."\n";
  $fp = fopen('data.txt', 'a+');

    if(fwrite($fp, $text))  {
        echo 'saved';

    }
fclose ($fp);    
}
$lines = file("data.txt"); // Get the file as an array
$lines = array_unique($lines); // Merge all duplicate lines
// Save as a new file
$file = fopen("datacurated.txt", "w");
fwrite($file, implode("", $lines));
fclose($file);
?>

所以 html 文件并不是很重要,但我不太擅长编码我试图通过 vscode 发送一个发布数据请求但没有工作。 我想知道是否有可能摆脱 html 文件并保持 php 在线并让它写入所需的数据。我还需要 php 文件中的删除重复文本功能。 这可以在 vscode 中使用 AXIOS 吗?

【问题讨论】:

  • Node 是如何/从哪里进来的?
  • 节点程序运行良好我想制作一个单独的node.js文件,将用户名数据写入php并提交
  • 如果可能的话,去掉 html
  • 我认为您需要对原始问题进行澄清。 1.program.js在哪里? 2. 从哪里挑出一个用户名字段? 3.“在线文件”是什么/在哪里? “通过php提交”是什么意思?
  • 你有那个“在线表格”的网址吗?

标签: php html node.js forms


【解决方案1】:

由于 request 软件包已被弃用,请改为安装 got

然后是你的节点代码:

(async () => {
  const { body } = await got.post("https://www.website.com/submit.php", {
    json: {
      username: "Whatever..."
    }
  });
  console.log(body);
})();

你不关心www.website.com/submit.php 是用什么写的,但你必须确定该服务器会接受来自你计算机的 Http Post 请求。他们通过过滤掉您的域或添加验证码来阻止您尝试做的事情是微不足道的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    相关资源
    最近更新 更多