Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA HTTP POST not working

Tags:

ms-word

vba

I am trying to send HTTP post through VBA. Here is my part of code

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "POST", url, False
objHTTP.setRequestHeader "User-Agent", "EPS 1.0"
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.setRequestHeader "content", postString
objHTTP.setRequestHeader "Content-Length", Len(postString)
objHTTP.send

The problem is, the code is working only if the postString is less than 65535 characters. If it exceeds 65535 characters, it throws error on below line:

ERROR: Incorrect parameter

objHTTP.setRequestHeader "content", postString

Any ideas about this? Do I need to set any other parameter to make it work around?

like image 222
Linga Avatar asked Jun 27 '15 13:06

Linga


1 Answers

Per: https://support.microsoft.com/en-us/kb/290591

This should work:

postString = "id=" & String(66000,"x")
Dim xmlhttp 
Set xmlhttp = Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send postString

If it does not work, then maybe there's something going on with your server-side setup.

like image 60
Tim Williams Avatar answered Nov 11 '22 01:11

Tim Williams