bishop3000
asked on
VBA -- XMLHTTP POST method not working
Hi,
I'm trying to upload data to a web server for the first time.
The VBA function I'm using is below. This is for Excel 2007.
As it is now, I get the error code 500 ("Internal Service Error") when adding msgbox XmlHttp.Status at the end of the function.
The XmlText variable I'm using can be recreated using the attached file.
I'm very confident that the URL, UserName, and Password I'm using are correct (I've successfully used the GET method for a different objective with this web server). Unfortunately, I can't post those things here due to non-disclosure issues.
Straightforward documentation from the web server is available here:
https://www.powerclerkdemo.com/AppUpload/Schema/ApplicationUpload/ApplicationUpload.aspx
They say their service is exposed via a RESTful API. Maybe the function I'm using assumes SOAP. I don't know the difference as far as VBA is concerned.
Any suggestions greatly appreciated.
Regards,
Michael
I'm trying to upload data to a web server for the first time.
The VBA function I'm using is below. This is for Excel 2007.
As it is now, I get the error code 500 ("Internal Service Error") when adding msgbox XmlHttp.Status at the end of the function.
The XmlText variable I'm using can be recreated using the attached file.
I'm very confident that the URL, UserName, and Password I'm using are correct (I've successfully used the GET method for a different objective with this web server). Unfortunately, I can't post those things here due to non-disclosure issues.
Straightforward documentation from the web server is available here:
https://www.powerclerkdemo.com/AppUpload/Schema/ApplicationUpload/ApplicationUpload.aspx
They say their service is exposed via a RESTful API. Maybe the function I'm using assumes SOAP. I don't know the difference as far as VBA is concerned.
Any suggestions greatly appreciated.
Regards,
Michael
Function PostXmlData(vURL As String, UserName As String, Password As String, XmlText As String) As String
Dim XMLHttp As Object
Set XMLHttp = CreateObject("MSXML2.XMLHTTP")
XMLHttp.Open "POST", vURL, False, UserName, Password
' Not sure which 'setRequestHeader' to use, if any.
'XMLHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" ' Status error 400 returned (Bad Request)
XMLHttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8" ' Status error 500 returned (Internal Service Error)
XMLHttp.send (XmlText)
PostXmlData = XMLHttp.responseText
End Function
XmlText-Code.xls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you sure you can leave out the requestheader called content-length? It might not be necessary - but do check it...
XMLHttp.setRequestHeader "Content-Length" , Str(Len(XmlText))
I can't see from your code that you are supplying a valid API-key either...
In a post it should be sent as a part of any request according to the links you provided...