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.