HTTPBuilder不可接受的错误

时间:2014-09-02 16:47:38

标签: groovy 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'
    }
}

任何想法?

1 个答案:

答案 0 :(得分:0)

鉴于HTTP不可接受意味着:

  

406不可接受

     

请求标识的资源只能生成   具有不可接受的内容特征的响应实体   根据请求中发送的接受标头。

然后他们的API可能很挑剔,您需要使用Accept标题指定您希望响应为JSON,使用类似Accept: application/json的内容。