LoginSignup
0
0

「curl: (3) bad range in URL」エラーの解決方法

Last updated at Posted at 2024-06-28

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 が特殊文字をファイルパスのワイルドカードとして解釈するのを防ぎます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0