Вопрос

When I am using Dispatch library and Scala, for debugging purpose, how to print out the entire HTTP request with headers, etc. in text after writing a statement like this ?

val svc = url("http://api.hostip.info/country.php")
Это было полезно?

Решение 2

Assuming you're using the latest version of the lib, url(...) returns a Req, which is just a thin wrapper around com.ning.http.client.RequestBuilder. You can get the underlying request object with svc.toRequest, which you can then call toString on or combine the other methods available depending on what information you're really after. More info:

Java doc for Request

Source for dispatch

Другие советы

Dispatch is based on Netty.io, which fully implements the sl4j logging facade. The debug logging is already being done for you by:

com.ning.http.client

Beware, it logs a LOT of crap. I am assuming you are using ch.qos.logback for logging purposes:

Go to src/main/resources, create a file called default.logback.xml, and add the following to it:

<configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
  </appender>

  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top