curlの実行で「curl: (3) bad range in URL」というエラーが出て困った時の対処方法です。
現象
以下のようなcurlコマンドを実行すると curl: (3) bad range in URL position 55:
というエラーが発生しました。
$ curl -X GET "http://localhost:3000/hogeapi/search?sort[column]=code&sort[direction]=asc" -H "accept: application/json"
curl: (3) bad range in URL position 55:
http://localhost:3000/hogeapi/search?sort[column]=code&sort[direction]=asc
^
解決策
--globoff
オプションを追加する。
curl --globoff -X GET "http://localhost:3000/hogeapi/search?sort[column]=code&sort[direction]=asc" -H "accept: application/json" -H "X-Request-ID: 99c15ac0-2fd8-4d16-bfe4-6b65b08e3077" -H "Accept-Language: ja-JP" -H "USER-ID: 1" -H "AUTHORITIES: \"[\"sys_admin\"]\""
原因
URLの sort[column]
あたりでエラーになっているようでした。
クエリパラメータに特殊文字([
と ]
)が入っており、 curl
が自動的にエスケープ処理を行っていました。
-globoff
オプションを使うと、このエスケープ処理が無効化され、URL に含まれる特殊文字をそのまま使えます。
curl
が特殊文字をファイルパスのワイルドカードとして解釈するのを防ぎます。