25
-dオプションを指定してcurlコマンドを送信して、現在のディレクトリのファイルではなくパスを指定してファイルを指定する方法については、絶対パスまたは相対パスのcurl要求でjsonファイルを送信する
これは、ローカルディレクトリ内のjsonファイルを使用してアプリケーションをテストしようとするときに発生します。アプリと私の両方が満足している:
curl -XPOST -H 'Content-Type:application/json' -d @all_fields.json http://testcomp.lab.net:8080/stats -v -s
* About to connect() to testcomp.lab.net port 8080
* Trying 10.93.2.197... connected
* Connected to testcomp.lab.net (10.93.2.197) port 8080
> POST /stats HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: testcomp.lab.net:8080
> Accept: */*
> Content-Type:application/json
> Content-Length: 2882
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 200 OK
< Content-Length: 0
* Connection #0 to host testcomp.lab.net left intact
* Closing connection #0
これは私が別のディレクトリにありますJSONファイルを指定するとき、私は取得しています
curl -XPOST -H 'Content-Type:application/json' -d @json/all_fields.json http://testcomp.lab.net:8080/stats -v -s
"Invalid json for Java type interface java.util.List"
Warning: Couldn't read data from file "json/all_fields.json", this makes an
Warning: empty POST.
<snip snip>
<snip snip>
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Transfer-Encoding: chunked
* Connection #0 to host testcomp.lab.net left intact
* Closing connection #0
私はmanページには何も見なかったものですデータとして渡されるファイルのディレクトリを指定するためのカール。残念なことに、ローカルディレクトリのファイルに限定されているのですか、別のディレクトリにファイルを指定する特別な方法はありますか?あなたの助けを前にありがとう。
ありがとう、返信ありがとうございます。相対パスまたは絶対パスを入れても機能せず、パスも存在します。あなたのcmdを実行したときにどのバージョンのカールを使用しましたか?私のものはカールです7.24.0(x86_64-apple-darwin12.0)libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5。私はちょうどあなたが上に書いたことは、私がやったことですが、それは動作していないのb/cで起こっているものを把握しようとしているほとんどのウィットの終わりです。 – Classified
curl 7.21.4(universal-apple-darwin11.0)libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5 – Perception
これはカールバージョンの違いによって引き起こされる可能性がありますか? jsonファイルへのパスが有効です。しかし、私にとって、curl cmdでパスを使用すると、動作しません。私がcurl cmdを実行し、ファイルがローカルディレクトリにある場合、それは動作します。 – Classified