1

I' am using groovy to consume a POST Rest api : here is my code :

    import groovyx.net.http.RESTClient
    @Grab (group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.7.1')
def url = "https://poc-ser.tst.be/"
def client = new RESTClient(url)
client.ignoreSSLIssues()
client.auth.basic(login,pswd)

client.post(
  path: "osidoc/api/rest/production/documents?id=46",
  contentType:'application/json',
  headers: [Accept: 'application/json' , Authorization: 'Authorization']
  )

But I always get error " error groovyx.net.http.ResponseParseException: OK caused by: groovy.json.JsonException: Unable to determine the current character, " Knowing that the response should be "application/msword" type (i.e : the response should be a word doc)

EDIT

I tried to change the Accept to "application/octet-stream' but it showed me an other error "406Invalid Accept header. Only XML and JSON are supported.`"

MAryem
  • 182
  • 1
  • 2
  • 14
  • you are requesting json from server with header: `Accept: application/json`. try to set `application/octet-stream` – daggett Aug 29 '20 at 12:37
  • @daggett I ve tried that but it shows me an other error "406 Invalid Accept header. Only XML and JSON are supported" – MAryem Aug 29 '20 at 12:40
  • so, server saying you should request only json or xml. however when you are requesting json - client fails to parse this json. go to api developer and ask him what to do (IHMO).. – daggett Aug 29 '20 at 13:08
  • btw, remove `Authorization: 'Authorization'` header because you are already setting it through `client.auth.basic(...)` – daggett Aug 29 '20 at 13:09

0 Answers0