I need to send a POST request from an MS Access VBA script to a remote PHP script to return database data. The VBA script works fine but I can't send a required parameter.
VBA
Set oXHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
oXHTTP.Open "POST", URL, False
oXHTTP.setRequestHeader "Content-Type", "application/json"
oXHTTP.send "getorglist=true"
doCURL = oXHTTP.responseText
PHP
if(filter_has_var(INPUT_POST, 'getorglist')) {
echo json_encode(getOrgList($pdo));
return;
}
The VBA script works, returns a 200 response, but empty data. If I remove all but the middle line of the PHP script the correct JSON code is returned.
What needs to be changed?
After some online searches and experiments, I find that the solution is to replace line 3 in the VBA code (the setRequestHeader
line) with:
oXHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
This works, but I can't see why, which is troubling. Can somebody advise?