Rochdi Badis · May 17, 2022

Get HTTP response using Token

Hi Guys,

I'm using the below code to get a JSON file using a Token, I can get json file with not problem from the the command prompt as below,

curl -X 'POST' \
  '' \
  -H 'accept: */*' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiIxNCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2VtYWlsYWRkcmVzcyI6ImFzYWJvNjQ3MzhAZ21haWwuY29tIiwiUGVybWlzc2lvbiI6WyJBY2NvdW50X01hbmFnZW1lbnQiLCJXb3JrUmVxdWVzdF9DcmVhdGUiLCJXb3JrUmVxdWVzdF9WaWV3TGlzdCIsIldvcmtSZXF1ZXN0X0FwcHJvdmUiLCJXb3JrUmVxdWVzdF9TY2hlZHVsZVdvcmtPcmRlckFjdGl2aXR5IiwiV29ya1JlcXVlc3RfQ2FuY2VsIl0sImV4cCI6MTY1MTY5Nzg1MSwiaXNzIjoiR2FsYXh5QXBpIiwiYXVkIjoiaHR0cHM6Ly92aWJyYS1hcGktZGV2LmF6dXJld2Vic2l0ZXMubmV0In0.O7WFmDZVWEUx26o3G8iZ-pULBoprZviq9yaCP0572Gk' \
  -d ''


but my code in my class method is not working, what an I missing? 

 set Httprequest = ##class(%Net.HttpRequest).%New()
  Set Httprequest.SSLConfiguration="RTLS"                              
  Set Httprequest.Server="serverurl"                 
  Set Httprequest.Https=1
  Set Httprequest.Timeout=30
   set Httprequest.ContentType="application/json"
Do Httprequest.SetHeader("Accept","application/json")
Do Httprequest.SetHeader("Authorization","Bearer "_Token)
   set tSc = Httprequest.Post("/api/jobs")
  //S Resp=Httprequest.HttpResponse.Data.ReadLine()
   Set Resp=Httprequest.HttpResponse.Data.Read()
   Quit Resp


Product version: Ensemble 2014.1
0 253
Discussion (3)1
Log in or sign up to continue

It looks like in your curl you have the Accept header as */*, but in your HttpRequest object, you're setting it to "application/json". Does that make a difference?

Nope, changed it to */* and didn't make any diffrence.

in the Token there are "." & "_"   special charachters not sure if that cause problem, I tried removed them but still no luck.