私は、次のコマンドを実行すると、すべてが素晴らしい作品:カールでWebサービスへのアクセス、/ binに/ shスクリプトでは、「HTTP 415サポートされていないメディアタイプは」原因
curl -s -o /dev/null -w %{http_code} \
http://www.example.com/mywebservice/generic.example.com \
--header "Content-type: application/json" --request PUT \
--data '{"hostname":"generic.example.com", "project":"none", "usage":"generic", "environment":"production"}'
私はにこのコマンドを入れた場合
#!/bin/sh
read -d '' CMD << EOF
curl -s -o /dev/null -w %{http_code} http://www.example.com/mywebservice/generic.example.com \
--header "Content-type: application/json" --request PUT \
--data '{"hostname":"generic.example.com", "project":"none", "usage":"generic", "environment":"production"}'
EOF
`$CMD`
私はそれをプリントアウトして、コマンドを確認し、それは次のように例になります:/ binに/ shスクリプト内の変数、およびそれを実行、私は「HTTP 415サポートされていないメディアタイプが」サーバログに現れてもらいますマニュアルを実行する:
#!/bin/sh
read -d '' CMD << EOF
curl -s -o /dev/null -w %{http_code} http://www.example.com/mywebservice/generic.example.com \
--header "Content-type: application/json" --request PUT \
--data '{"hostname":"generic.example.com", "project":"none", "usage":"generic", "environment":"production"}'
EOF
echo $CMD
出力:
カール-s -oを/ dev/null -w%{HTTP_CODE} http://www.example.com/mywebservice/generic.example.com "コンテンツタイプ:アプリケーション/ JSON" --headerは--data PUT --request「{」ホスト名は、 ":" generic.example.com」、 "プロジェクト": "なし"、 "使い方": "一般的な"、 "環境": "生産"}」私にとって
ヘッダーはどのように見えますか( '-i'フラグを追加するか、より冗長にするために' -v')を送信しますか?それはまだ同じですか? –
@peeskillet -vは間違いなく有益でした。バットから離れて、 "Content-Type:application/x-www-form-urlencoded"と表示され、コマンドは--header引数を正しく見ていなかった。私はこれがコマンドラインにコマンドを入れることに問題があると思う。私はたぶん変数なしで実行します。 – wsaxton
私は同じ問題に遭遇しました。あなたはそれを@wsaxtonで把握できましたか? – Masked