Question
Rochdi Badis · May 30

HTTP/1.1 500 Internal Server Error

Hi Guys,

I'm using the below code to post a JSON file:

 FilePath="D:\Allied_InterfaceData\ResponseFiles\CollectionData\CollectionGood\CollectionGood_9503948.json"
 Set File = ##class(%File).%New(FilePath)
Do File.Open("R")
  Set Httprequest=##class(%Net.HttpRequest).%New()
Set Httprequest.SSLConfiguration="RTLS"
Set Httprequest.Server="vibra-api-dev.azurewebsites.net"
Set Httprequest.Timeout=30
Set Httprequest.Https=1
set Httprequest.ContentType="application/json"
Do Httprequest.SetHeader("Accept","*/*")
  Do Httprequest.SetHeader("Authorization","Bearer "_^Token)
 While ('File.AtEnd) {
    Line=Line_File.Read(1000)_$char(10)
  }
  do Httprequest.EntityBody.Write(Line)
Set tSc=Httprequest.Post("/api/sensors/vibration")
Set StateCode=Httprequest.HttpResponse.StatusCode
Set State=Httprequest.HttpResponse.StatusLine
Quit StateCode_"|"_State
 

the required schema is:

{
  "routeGuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "jobGUID": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "id": 0,
  "sensorId": "string",
  "sensorType": "string",
  "sensorModel": "string",
  "sensorHardwareVersion": "string",
  "sensorFirmwareVersion": "string",
  "sensorTemperature": 0,
  "sensorBatteryVoltage": 0,
  "sensorRSSI": 0,
  "gatewayMAC": "string",
  "gatewayContainerVer": "string",
  "gatewayAppVer": "string",
  "measurementDateTime": "string",
  "measuredTemperature": 0,
  "opSpeed": 0,
  "sampleDuration": 0,
  "sampleRate": 0,
  "totalLines": 0,
  "bleMac": "string",
  "collectionNotes": "string",
  "dcOffset": [
    0
  ],
  "lines": [
    [
      0
    ]
  ]
}

and attached is the file I'm trying to send my I'm getting : HTTP/1.1 500 Internal Server Error , and I'm wondering what I'm doing wrong?

 

 

 

Thanks

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

Hi Rochdi,

The HTTP error 500 indicates that something happened in the server that's cause a error.

I suggest you to do a test using postman or similar REST tool. If the works fine, maybe you can posted the JSON with some problem.

Another suggest, change your code :

 While ('File.AtEnd{
    Line=Line_File.Read(1000)_$char(10)
  }
  do Httprequest.EntityBody.Write(Line)

By:
  do Httprequest.EntityBody.CopyFrom(File)

Regards.

Thanks Cristiano for you help.

By the way do I need to add :

D File.Open('R') before using  copy From  or just initialising the file is enough?

Thx

Hi.

Line=""
While ('File.AtEnd{
    Line=Line_File.Read(1000)_$char(10)
  }

You need to declare variable Line before you concatenate it (or use $Get(Line,"")).

Regards,
Matjaž 

P.S.
It is better way to use stream as Crisitano suggested...