2012-03-28 22 views

回答

20
request.body 

,您可以訪問請求身體。所以,如果它是XML,你想把它當作一個NodeSeq,做到:

XML.loadString(request.body) 
+0

+1,「回答」 – virtualeyes 2012-03-28 17:26:41

+0

確保Content-Type不是'application/x-www-form-urlencoded'(請參閱https://groups.google.com/forum/#!topic/scalatra-user/lApjIJXiNqg上的Ross答案) – uthomas 2013-11-03 02:09:52

4

+1,好問題

你有Scalatra的路線內通過「請求」關鍵字訪問servlet請求,所以和的getInputStream提供getContentLength如果訪問後身體本身的XML字符串;即客戶端而不是傳遞存儲在命名字段中的xml作爲表單發佈的一部分。如果是後者,那麼下面應該做的伎倆:

post("/foo" && request.getHeader("Accept-Encoding") contains "application/xml") { 
    val xml = XML.fromString(params("xml-param-field-name")) 
} 

如果你想使用上面的字符串解析,請參閱反垃圾XML集成在Scalatra Book

+0

是新來斯卡拉和&& /包含這樣^^我得到的編譯錯誤。 – 2017-04-28 13:33:21

+0

@ gursahib.singh.sahni不確定,自從我使用Scalatra以來已經有5年了;-)也許試試他們的[Gitter頻道](https://gitter.im/scalatra/scalatra) – virtualeyes 2017-04-29 10:18:31

相關問題