2012-08-15 44 views
2

試圖將多個標題添加到Scala Play! WS要求:Play中有多個標題的精確語法! 2.0 WS請求?

WS 
.url(requestUri) 
.withHeaders("Authorization" -> ("Oauth %s" format(cred.authorizedToken)), 
    "Content-Type" -> "application/json") 
.post(httpBody.get) 

但是它目前失敗。什麼是適當的語法?我試過多種方法,但編譯器抱怨java字符串。謝謝!

+0

我沒有帶試過,但你似乎approche與源代碼正確'高清withHeaders(hdrs:(String,String)*)'。這種語法也記錄在這裏http://www.playframework.org/documentation/2.0.2/ScalaResults – 2012-08-15 14:02:25

+0

有趣的是,我不知道發生了什麼。該線程正在執行沒有標題,現在它似乎超時。我會繼續在thx – crockpotveggies 2012-08-15 16:19:00

+0

實驗如果解決了,我會發佈一個真正的答案:) – 2012-08-15 16:19:50

回答

3

你的方法根據documentation

Ok("Hello World!").withHeaders(
    CACHE_CONTROL -> "max-age=3600", 
    ETAG -> "xx" 
) 

而且該方法的定義驗證碼也似乎有效:

def withHeaders(hdrs: (String, String)*) 
// Parameters are infinite couples of String 
+0

感謝分享。它與ScalaWS doc示例顯然不同,因爲它有多個頭。乾杯 – crockpotveggies 2012-08-15 16:34:01

相關問題