Avatar of lucidity_99

asked on 

Can't push data to PHP correctly with MSXML2.ServerXMLHTTP from VBA


I'm trying to push some data to a PHP script on a Linux box from VBA.

The code runs fine and appears to push everything to the server correctly.  However, on the server side, the PHP $_POST variable is empty, as is $_REQUEST, $_SERVER['HTTP_RAW_POSTDATA'], etc.

The only way I can currently see what is being transmitted is with file_get_contents('php://input'), which is no good.

I think it has something to do with Unicode/UTF-8 encoding, but I'm at a loss.  I found the URLEncode() function on the internet and using that allowed me to at least see the data in php://input, but I can't get any further.

Any help would be much appreciated!
Function Upload_Data() 
    Dim strPOSTData As String, strFieldValue As String
    Dim xmlhttp As Object
    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    strGLDepartment = DLookup("[GLDepartment]", "[tblUnit]")
    strPOSTData = "gldepartment=" & strGLDepartment
    xmlhttp.Open "POST", "http://XXXX/employees.php", False
    xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded" + Chr(10) + Chr(13)
    xmlhttp.send URLEncode(strPOSTData)
    If xmlhttp.Status >= 400 And xmlhttp.Status <= 599 Then
      Debug.Print "Error Occurred : " & xmlhttp.Status & " - " & xmlhttp.StatusText
      Debug.Print xmlhttp.responseText
    End If
    Set xmlhttp = Nothing
End Function
Function URLEncode(strData)
  Dim I, strTemp, strChar, strOut, intAsc
    strTemp = Trim(strData)
    For I = 1 To Len(strTemp)
        strChar = Mid(strTemp, I, 1)
        intAsc = Asc(strChar)
        If (intAsc >= 48 And intAsc <= 57) Or (intAsc >= 97 And intAsc <= 122) Or (intAsc >= 65 And intAsc <= 90) Then
            strOut = strOut & strChar
            strOut = strOut & "%" & Hex(intAsc)
        End If
    URLEncode = strOut
End Function

Open in new window

Microsoft AccessXMLPHP

Avatar of undefined
Last Comment

8/22/2022 - Mon