How to send an API request within MS Access with an entity body field for ANPR IP camera?

54 Views Asked by At

I need to add and read vehicle plate numbers from a white list in an ANPR camera. I've got a code from the manufacturer TVT, but I'm not able to send it to the camera or get a response. Usually I send the API only in the form of (for example)

XMLHTTP.Open "GET", "https://www.psc.cz/?search=" & Ulice & "%2C+" & Mesto & "&send=Odeslat&do=searchForm-submit", False

, but I can't add the xml code of entity body field according to the manufacturer:

<config xmlns="http://www.ipc.com/ver10" version="1.7">
 <vehiclePlates type="list" maxCount="10000" count="1">
  <searchFilter>
   <pageIndex type="unit32">1300</pageIndex>
   <pageSize type="unit32">1</pageSize>
   <listType type="unit32">0</listType>
   <carPlateNum type="string">0</carPlateNum>
  </item>
 </searchFilter>

There are also mentioned some headers necessary fot the request such as Connection Header and Authorization Header.

Would anyone push me any further to correctly specify the VBA code in Access in order to succeed and add a vehicle plate number to the camera list? Would be very appreciated...

I've already tried...

Dim XMLHTTP As MSXML2.XMLHTTP60

Set XMLHTTP = New MSXML2.XMLHTTP60

XMLHTTP.Open "GET", "http://192.168.10.147:80/GetVehiclePlate", False
XMLHTTP.SetRequestHeader "Content-Type:", "application/xml; charset=""UTF-8"""

XMLHTTP.SetRequestHeader "Authorization", "Basic " + "YWRtaW46YWRtaW4="
XMLHTTP.SetRequestHeader "Config", "xmlns" + "http://www.ipc.com/ver10"" version=""1.7"
XMLHTTP.SetRequestHeader "Connection", "Keep-Alive"

XMLHTTP.Send "<config xmlns=""http://www.ipc.com/ver10"" version=""1.7"">" & _
             "<vehiclePlates type=""list"" maxCount=""10000"" count=""1"">" & _
             "<searchFilter> " & _
             "<pageIndex type=""unit32"">1300</pageIndex>" & _
             "<pageSize type=""unit32"">1</pageSize>" & _
             "<listType type=""unit32"">0</listType>" & _
             "<carPlateNum type=""string"">0</carPlateNum>" & _
             "</item>" & _
             "</searchFilter>" & _
             "</config>"

Do Until XMLHTTP.ReadyState = 4
    DoEvents
Loop
byteData = XMLHTTP.responseBody

Debug.Print StrConv(byteData, vbUnicode)

Still getting an error 499. No plates number in response.

FINALY I SUCCEEDED. The working code looks like:

DIM plateNr as STRING ' your real vehicleplate number, you are looking for
                      ' empty for all numbers
GetVehiclePlate = "<?xml version=""1.0"" encoding=""utf-8"" ?>" & vbNewLine & _
              "<config>" & vbNewLine & _
              "<searchFilter> " & vbNewLine & _
              "<pageIndex type=""unit32"">0</pageIndex>" & vbNewLine & _
              "<pageSize type=""unit32"">10</pageSize>" & vbNewLine & _
              "<listType>allList</listType>" & vbNewLine & _
              "<carPlateNum type=""string"">" & plateNr & "</carPlateNum>" & vbNewLine & _
              "</searchFilter>" & vbNewLine & _
              "</config>"

XMLHTTP.Open "POST", "http://192.168.10.147/GetVehiclePlate", False
XMLHTTP.SetRequestHeader "Content-Type:", "application/xml; charset=""UTF-8"""

XMLHTTP.SetRequestHeader "Authorization: ", "Basic " + "YWRtaW46YWRtaW4="
XMLHTTP.SetRequestHeader "Config: ", "xmlns" + "http://www.ipc.com/ver10"" version=""1.7"
XMLHTTP.SetRequestHeader "Connection: ", "Keep-Alive"
XMLHTTP.SetRequestHeader "Size: ", Len(GetVehiclePlate)

XMLHTTP.Send GetVehiclePlate

Do Until XMLHTTP.ReadyState = 4
  DoEvents
Loop
byteData = XMLHTTP.responseBody

Debug.Print StrConv(byteData, vbUnicode) 'the XML answer
0

There are 0 best solutions below