Bash CGIスクリプトのCurlコマンドにXML出力は表示されません。 [データが表示されない]

Bash CGIスクリプトのCurlコマンドにXML出力は表示されません。 [データが表示されない]

Linux シェルでこのコマンドを実行すると、

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

XMLデータの代わりに、次の表がWebブラウザに表示されます。

  % 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コマンドでカールの詳細を使用すると、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

ご協力ありがとうございます。

ベストアンサー1

あなたが見るテーブルは、それが何をしているのかについてのカールの情報出力です。 STDERRに移動します。 STDERRをSTDOUT()にリダイレクトしているので、2>&1これを見ているのです。

を追加してリダイレクトを削除するか、カール出力をサイレントにする必要があります--silent。目的の出力が得られない理由は完全には明確ではありませんが、| tee最終的に重複しているように見え、ターゲットファイル名が見つからないため役に立ちません。

おすすめ記事