1

我在 http4s 中做一个简短的任务,很长一段时间以来我都收到了 403 错误,这很难调试。我的代码是:

object Assignment extends App {
  implicit val cs: ContextShift[IO] = IO.contextShift(global)
  implicit val timer: Timer[IO] = IO.timer(global)
  val blockingPool = Executors.newFixedThreadPool(5)
  val blocker = Blocker.liftExecutorService(blockingPool)
  val httpClient: Client[IO] = JavaNetClientBuilder[IO](blocker).create
  //val httpize = Uri.uri("http://httpize.herokuapp.com")

  def get() = {
    /*val target = uri("http://www.randomtext.me/download/txt/lorem/p-1/10-35/")
    val req = Request(method = Method.GET, uri = target)*/
    val ioString = httpClient.expect[String]("http://www.randomtext.me/download/txt/lorem/p-1/10-35/")
    val futu = ioString.map(x => x)
    futu.map(_.mkString).unsafeRunSync()





  }
  /*def post() = {
    val req = Request(method = Method.POST, uri = httpize / "post").withBody("hello")
    val task = httpClient.
    val x = task.unsafePerformSync
    println(x)
  }*/
  get()

  // post()

}
4

0 回答 0