【问题标题】:Curl shell script not giving variables to php file卷曲外壳脚本没有将变量提供给 php 文件
【发布时间】:2015-08-30 20:46:34
【问题描述】:

我想要什么

通过 Apple 脚本,我可以从本地计算机获取一些信息。现在我希望将这些信息写入 MySQL 数据库。

我的代码

现在我正在获取我的所有信息并将它们写入变量。然后我正在创建一个 URL 以将这些信息传输到我的 PHP 脚本,该脚本处理写入数据库的内容。在这个创建的 URL 字符串中,我用 "%20" 替换所有空格(因为 URL 友好)。

现在我正在运行一个带有 curl 导航到指定 URL 的 shell 脚本。

set aString to "http://localhost/clientinfo/setlogin.php?a=" & info_hostname & "&b=" & info_modelname & "&c=" & info_macaddress & "&d=" & info_osversion & "&e=" & info_cpuname & "&f=" & info_cpuspeed & "&g=" & info_ram & "&h=" & info_serial

set my text item delimiters to " "
set split_list to every text item of aString
set my text item delimiters to "%20"
set newString to (split_list as text)

do shell script "curl " & newString

所有编码后生成的 URL 如下所示:

http://localhost/clientinfo/setlogin.php?a=hostname&b=Mac%20mini&c=0c:4d:e9:ee:d5:58&d=10.9&e=Intel%20Core%20i5&f=2.5%20GHz&g=8%20GB&h=C07MW1XMH

问题

PHP 脚本告诉我,第一个变量之后的所有其他 "$_GET" 变量都没有指定。

curl 输出片段:

<b>Notice</b>:  Undefined index: b in <b>setlogin.php</b> on line <b>5</b><br />

当我输出生成的 URL 并将其输入到浏览器的地址栏中时,它可以工作。

curl 脚本有什么问题?

【问题讨论】:

  • 如果你使用 &而不是 & ?
  • 仍然无法工作@PerroVerd
  • 向 curl 命令添加详细/跟踪参数,看看它输出的关于它正在发送的请求的内容?

标签: php mysql shell curl


【解决方案1】:

脚本的最后一行是调用 curl 和生成的查询,问题似乎是通过 shell 运行,并且 & 它是一个特殊字符(将东西放在后台)所以可能你需要使用引号来避免字符串被解释

do shell script "curl \"" & newString & "\""

【讨论】:

  • 完美!这就是解决方案..谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-05-09
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 1970-01-01
相关资源
最近更新 更多