bash CGI脚本中的卷曲命令未显示XML输出[未显示数据]

用户名

如果我在linux shell中运行此命令。

curl=`curl --connect-timeout 4 -k -X POST -H "Content-type: text/xml" --data "<MyRequest><HeartBeat timestamp=\"1311157780201\"></HeartBeat></MyRequest>" http://192.168.1.100:8484/rest/service?action=heartbeat 2>&1 | tee`

echo "$curl"

我得到以下回应

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MyResponse><HeartBeat status="SUCCESS"></HeartBeat></MyResponse>

但是,当在bash CGI脚本中执行相同的命令并在html pre标签中显示输出时,我看到了一些奇怪的表,并且根本没有显示XML数据。

在CGI bash脚本中,我有此代码

    curl=`curl --connect-timeout 4 -k -X POST -H "Content-type: text/xml" --data "<MyRequest><HeartBeat timestamp=\"1311157780201\"></HeartBeat></MyRequest>" http://192.168.1.100:8484/rest/service?action=heartbeat 2>&1 | tee`

echo "<h2> RAW Troubleshooting Data </h2><pre>"
echo "$curl"
echo "</pre>"
exit 0

下表显示在Web浏览器中,而不是XML数据。

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  

Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0    76      0    424 --:--:-- --:--:-- --:--:--   424
202   126    0   126    0    76    302    182 --:--:-- --:--:-- --:--:--   210

但是,如果我在cgi bash脚本中使用带有-v命令的curl冗长性,则会在Web浏览器中得到跟踪,但仍然缺少XML响应。

* About to connect() to xx.xx.xx.xx port xxxxx (#0)
*   Trying xx.xx.xx.xx... connected
* Connected to xx.xx.xx.xx (xx.xx.xx.xx) port xxxxx (#0)
> POST /rest/service?action=heartbeat HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: xx.xx.xx.xx:xxxx
> Accept: */*
> Content-type: text/xml
> Content-Length: 76
> 
} [data not shown]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0    76      0    422 --:--:-- --:--:-- --:--:--   422< HTTP/1.1 200 OK
< Server: nginx
< Date: Thu, 14 Nov 2019 18:53:44 GMT
< Content-Type: application/xml
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< X-Powered-By: PHP/7.0.32
< 
{ [data not shown]

202   126    0   126    0    76    284    171 --:--:-- --:--:-- --:--:--   190
202   126    0   126    0    76    284    171 --:--:-- --:--:-- --:--:--   190* Connection #0 to host xx.xxx.xxx.xx left intact

* Closing connection #0

感谢您的帮助。

bxm

您看到的表是curl所做工作的信息输出。转到STDERR。您正在将STDERR重定向到STDOUT(2>&1),所以这就是您看到它的原因。

您需要通过添加删除该重定向或使curl输出静音--silent至于为什么没有得到想要的输出,这还不是很清楚,但是| tee最后看起来多余,并且缺少目标文件名,因此不会有帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章