【问题标题】:HTTPBuilder Not Acceptable errorHTTPBuilder 不可接受的错误
【发布时间】:2014-09-02 16:47:38
【问题描述】:

我收到此错误,但我的方法对我来说看起来非常好

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'
    }
}

有什么想法吗?

【问题讨论】:

  • 你遇到了什么错误?

标签: groovy httpbuilder


【解决方案1】:

鉴于 HTTP 不可接受意味着:

406 不可接受

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

那么也许他们的 API 很挑剔,您需要使用 Accept 标头指定您希望响应为 JSON,使用类似 Accept: application/json 的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    • 2018-10-21
    • 1970-01-01
    • 2017-04-08
    • 2013-12-18
    • 1970-01-01
    • 2015-03-17
    相关资源
    最近更新 更多