2017-05-12 6 views
0

私は、次のコマンドを実行すると、すべてが素晴らしい作品:カールで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」、 "プロジェクト": "なし"、 "使い方": "一般的な"、 "環境": "生産"}」私にとって

+0

ヘッダーはどのように見えますか( '-i'フラグを追加するか、より冗長にするために' -v')を送信しますか?それはまだ同じですか? –

+0

@peeskillet -vは間違いなく有益でした。バットから離れて、 "Content-Type:application/x-www-form-urlencoded"と表示され、コマンドは--header引数を正しく見ていなかった。私はこれがコマンドラインにコマンドを入れることに問題があると思う。私はたぶん変数なしで実行します。 – wsaxton

+0

私は同じ問題に遭遇しました。あなたはそれを@wsaxtonで把握できましたか? – Masked

答えて

1

は、それがこの方法を働いた:

#!/bin/sh 

read -d '' CMD << EOF 
`/usr/bin/curl -s http://localhost:8080/someurl \ 
    --header "Content-type: application/json"` 
EOF 

echo $CMD 

EOFの内部で評価するとどうなりますか?

関連する問題