0

I am trying to send a http POST using the following code :-

def http = new HTTPBuilder("https://api.somewhere.com/prod/rest/send")
http.request(Method.POST, ContentType.XML){
    headers.'Authorization' = 'Basic VW52ZDYW06NGblahblahY3'
    headers.'Accept' = 'application/xml'
    headers.'Content-Type' = 'application/xml'
    body: '<sendmess><sender>Granny</sender><message>Hello son</message><medium>carrier pigeon</medium></sendmess>'
        response.success = { resp, reader ->
            println "===============" + reader.text
            }
        }

But I am getting an error which simply says Unauthorized. I know the Authorization string is ok because I can do an http post to the server using curl :-

curl -k https://api.somewhere.com/prod/rest/send 
   -H "Content-Type: application/xml"
   -H "Accept: application/xml"
   -H "Authorization: Basic VW52ZDYW06NGblahblahY3" 
   -d "<sendmess><sender>Granny</sender><message>Hello son</message><medium>carrier pigeon</medium></sendmess>"

And this works just fine. But using the grails code above throws an exception saying Unauthorized at the line http.request. I know it is hitting the url as I've done a wireshark and I can see the comms between my machine and //api.somewhere.com so it must be the website saying Im unauthorised, but it works fine with curl?

Any help much appreciated.

Simon
  • 97
  • 3
  • 13
  • Just for info, I never did get to the bottom of this so I rowed back to using the Java HttpURLConnection technique, which seems to work just fine. – Simon Oct 18 '22 at 10:59

0 Answers0