gpt4 book ai didi

php - 如何从 ash (bash) 将数据发布到 php

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:56 24 4
gpt4 key购买 nike

我有 url (www.blabla.web.id/proses_data.php) 在线。我想从我的 bash 脚本向该 url 提交数据。我在 OpenWRT 中使用 ash、bash。

我正在尝试这种技术,

#!/bin/sh
elinks -dump http://www.blabla.web.id/proses_data.php?data=thisisthedata

但它使用GET 方法。如何使用POST方法?

最佳答案

elinks是一个以文本模式浏览网页的程序。您不能通过它发布数据。

但是 Linux 为 POST 数据提供了漂亮的工具

用这个漂亮的小命令

curl --data "param1=value1&param2=value2" http://hostname/resource

如果 Web 响应是 JSON 那么也可以 POST

curl -X POST  -H "Accept: Application/json" -H "Content-Type: application/json" http://someHostName/someEndpoint -d '{"id":"IDVALUE","name":"Mike"}' | grep }| python -mjson.tool

还有一些小技巧

php脚本中添加这个函数

function getInput() {
$fr = fopen("php://stdin", "r");
while (!feof ($fr)) {
$input .= fgets($fr);
}
fclose($fr);
return $input;
}

$takethis = getInput();

现在在 bash 中做喜欢

echo 22333333 | php my.php

关于php - 如何从 ash (bash) 将数据发布到 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22528075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com