2017-12-13 12 views
0

は、この例を見てみましょう:フォームを送信するときにカールがContent-Typeに追加されます。これを上書きする方法は?

curl http://host.compute-1.amazonaws.com:8080/oauth2/token -H "Content-Type: application/x-www-form-urlencoded" -F 'grant_type=password' -F 'username=test-user' -F 'password=password' -F 'client_id=test_application_client_id' -F 'client_secret=password' -v 

一つは、Content-Typeapplication/x-www-form-urlencodedに設定されるだろうと思うだろう。代わりにカールを送るapplication/x-www-form-urlencoded; boundary=------------------------5f55da42226c00e5

への道はありませんこれを行うには?カールmanページから

[email protected] ~/ $ curl http://something.compute-1.amazonaws.com:8080/oauth2/token -H "Content-Type: application/x-www-form-urlencoded" -F 'grant_type=password' -F 'username=test-user' -F 'password=password' -F 'client_id=test_application_client_id' -F 'client_secret=password' -v 
* Trying 0.0.0.0... 
* TCP_NODELAY set 
* Connected to something.compute-1.amazonaws.com (0.0.0.0) port 8080 (#0) 
> POST /oauth2/token HTTP/1.1 
> Host: something.compute-1.amazonaws.com:8080 
> User-Agent: curl/7.54.0 
> Accept: */* 
> Content-Length: 598 
> Expect: 100-continue 
> Content-Type: application/x-www-form-urlencoded; boundary=------------------------5f55da42226c00e5 
> 
< HTTP/1.1 100 Continue 
< HTTP/1.1 400 Bad Request 
< Server: Apache-Coyote/1.1 
< Date: Wed, 13 Dec 2017 00:43:13 GMT 
< Content-Type: text/plain 
< Content-Length: 145 
< Connection: close 
< 
* Closing connection 0 
WebApplicationException has been caught, status: 400, message: The Content-Type header is missing on this request you should define: Content-Type 

答えて

1

-F、--form (HTTP)これは、カールがエミュレートすることができます満たしているユーザーが送信ボタンを押した形。これは

などこれは、バイナリファイルのアップロードを可能にRFC 2388. に従ってContent-Typeのマルチパート/フォームデータを使用して データを投稿するカール

を引き起こし、あなたが-dとあなたの-Fを交換しようとしたことがありますか?ここで

は、私は両方で得るものです:-F

-d
$ curl -F "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://google.com -v 
* About to connect() to google.com port 80 (#0) 
* Trying 2a00:1450:400a:807::200e... 
* Connected to google.com (2a00:1450:400a:807::200e) port 80 (#0) 
> POST/HTTP/1.1 
> User-Agent: curl/7.29.0 
> Host: google.com 
> Accept: */* 
> Content-Length: 161 
> Expect: 100-continue 
> Content-Type: application/x-www-form-urlencoded; boundary=----------------------------5bb04ed0c4fe 
> 

$ curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://google.com -v 
* About to connect() to google.com port 80 (#0) 
* Trying 2a00:1450:400a:807::200e... 
* Connected to google.com (2a00:1450:400a:807::200e) port 80 (#0) 
> POST/HTTP/1.1 
> User-Agent: curl/7.29.0 
> Host: google.com 
> Accept: */* 
> Content-Type: application/x-www-form-urlencoded 
> Content-Length: 27 
> 
関連する問題