0

I am new to VBA so this is probably my problem. I am trying to perform a HTTP POST from Excel to a web service, and I can POST quite happily, until I change the code so that I am posting content in my message, at which point I get the following error:

Run-time error '-2147024809 (80070057)':

The Parameter is incorrect.

My code is as follows:

Dim oHttp As Object
Set oHttp = CreateObject("MSXML2.XMLHTTP.6.0")
Call oHttp.Open("POST", url, False)
oHttp.setRequestHeader "Content-Type", "application/text"
oHttp.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
Call oHttp.send(content)
httpPOST = oHttp.responseText

The line which is killing the code is the oHttp.send - if I do not pass any content then it is fine, as soon as I put content here it is unhappy.

The content parameter is a large string containing comma separated text and includes line feeds. I think this is why it is unhappy, if I change the string to simply a short "Hello" then the send is sucessful and the application happily makes it to the next line, before hitting the run-time error:

The data necessary to complete this operation is not yet available

So I guess my question is, how do I POST a large block of text to a server?

Thanks

2
  • You don't need Call or the the brackets wrapping the parameters for either of the two code lines they are used in. content is blank; while you may have removed the string assignment, you should have redacted it so we can see a version of what you are trying to pass into the post operation.
    – user4039065
    Feb 17, 2015 at 16:27
  • 1
    Maybe try encoding your data? stackoverflow.com/questions/17818903/… Also make sure your url is correctly formatted Feb 17, 2015 at 18:44

1 Answer 1

0

Thanks for the comments, I managed to get it to work by converting the string to a binary array and then send the binary array over.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.