2014-09-02 27 views
0

我得到這個錯誤,但我的方法看起來完全沒有給我HTTPBuilder不接受錯誤

def http = new HTTPBuilder() 

http.request(
    'https://textalytics-topics-extraction-11.p.mashape.com/topics-1.2?txt=ben',  
    Method.GET, 
    ContentType.JSON 
) { req -> 
    headers."X-Mashape-Key" = "mashkey" 

    response.success = { resp, reader -> 
     assert resp.statusLine.statusCode == 200 
     println "Got response: ${resp.statusLine}" 
     println "Content-Type: ${resp.headers.'Content-Type'}" 
     println reader.text 
    } 

    response.'404' = { 
     println 'Not found' 
    } 
} 

什麼想法?

+3

你得到了什麼錯誤? – Opal 2014-09-02 16:51:02

回答

0

鑑於HTTP不可接受的方法:

406不可接受

該請求所標識的資源只能能夠產生具有根據接受頭不能接受 內容特性 響應實體在請求中發送。

那麼也許他們的API是挑剔的,你需要指定你想要的迴應是JSON使用Accept頭,使用類似Accept: application/json