LoginSignup
3
2

More than 1 year has passed since last update.

WSLからWindowsのローカルサーバへHTTPリクエストする

Posted at

はじめに

Springの勉強中です。
APIを作成し動作確認をしたときに少し詰まりました。
その解決方法となります。

EclipseでWebアプリケーションを作成し、ローカルに実行すると、http://localhost:8080/でアクセス出来るかと思います。

同様に、API動作確認をWSL上のUbuntuからcurlコマンドで行いました。

$ curl -X GET http://localhost:8080/hoge
Failed to connect to localhost port 8080: 接続を拒否されました

とエラーを吐かれました。
答えは簡単で、WSLとWindowsはIPアドレスが異なるため、接続できるわけないよね。という結論です。

//コマンドプロンプト
> ipconfig
//実行結果のIPv4アドレスを次で使う

//WSL(Ubuntu)
$ curl -X GET 192.168.10.111:8080/hoge

これで動作確認できるはずです。

3
2
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
3
2