2

I am doing a short assignment in http4s and I am getting 403 error from a long time which is difficult to debug. My code is:

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()

}
  • Please consider using **IOApp** instead of **App**. - Also, it seems you do not get the idea of **IO** since you are running everything immediately. – Luis Miguel Mejía Suárez Feb 16 '20 at 16:35
  • Can reproduce [here](https://scastie.scala-lang.org/BalmungSan/ByqjD2NZSI2iFlq7FNhSuA). - I guess the problem is that the URL doesn't return a **String** _(text)_ but rathers downloads a file. – Luis Miguel Mejía Suárez Feb 16 '20 at 16:50
  • So what u are trying to say is that the problem with the url but i tries running the same url in postman and it responded back with a string – harshul dang Feb 17 '20 at 17:19
  • Actually, the code in the **Scastie** works, but something is blocking the connection. I just executed it on ammonite in my machine and it works as expected. – Luis Miguel Mejía Suárez Feb 17 '20 at 22:18

0 Answers0