LoginSignup
8
7

More than 5 years have passed since last update.

Play Scala で BASIC 認証ありのURLにHTTPリクエストを送信する

Last updated at Posted at 2016-01-04

Play には WS API というAPIがあり、これでHTTP関係の処理が行えます。

BASIC認証をやりたい場合は、リクエストに「withAuth」をつけるのがポイントです。APIドキュメントを見る限りでは、DIGEST認証など他の認証方式にも対応しているようです。

package controllers

import play.api.libs.ws.WSAuthScheme.BASIC
import play.api.libs.ws.WS
import play.api.mvc._

import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Application extends Controller with AdminSecure {

  def auth = Action.async {
    import play.api.Play.current
    WS.url("http://xxx:yyy/zzz").withAuth("admin", "password", BASIC).get().map(
      response => Ok(response.body)
    )
  }
}

8
7
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
8
7