12

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?

shA.t
  • 16,580
  • 5
  • 54
  • 111
Linga
  • 10,379
  • 10
  • 52
  • 104
  • What happens if you send your postString via `send`? So, comment out `objHTTP.setRequestHeader "content", postString` and amend `objHTTP.send postString` – TEK Jun 27 '15 at 13:14
  • @TEK I've tried and received no errors. But the response is failure meaning that the server didn't received any content – Linga Jun 27 '15 at 13:23
  • The reason is the server accepts only the contents posted through header. This is why I am sending via header – Linga Jun 27 '15 at 13:24
  • Odd that the server only accepts content up to 16 bits. Have you posted anything else to this server through different means to verify it can accept content greater than 16 bits? – TEK Jun 27 '15 at 13:28
  • Yes. It is working well when I post it through PERL and PHP – Linga Jun 27 '15 at 13:32
  • Humour me for one more minute, then I'll go away and think about it. Can you change the creation string from `MSXML2.ServerXMLHTTP` to `WinHttp.WinHttpRequest.5.1` and let me know what happens. – TEK Jun 27 '15 at 13:34
  • I'd tried that already but not worked – Linga Jun 27 '15 at 13:45
  • Its extremely odd to pass 65k as an HTTP **Header** value, that's way in advance of apache/iis default limits on request size - are you sure `postString` is not meant to be a *post string*? I.e the content of the request *body* as opposed to a header? – Alex K. Jun 27 '15 at 14:44
  • ```Content``` header? Shouldn't it be just ```objHTTP.send(postString)```? [Here](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) is no ```Content``` header specified. – Daniel Dušek Jun 27 '15 at 14:44
  • @AlexK. what do you mean? – Linga Jun 29 '15 at 06:14
  • @dee I already mentioned that, I'd tried `objHTTP.send(postString)` but I didn't receive any information on the server side – Linga Jun 29 '15 at 06:15
  • http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4 – Maciej Los Jun 29 '15 at 14:18
  • "The reason is the server accepts only the contents posted through header. This is why I am sending via header" - that is the OPPOSITE of POST, which as others have pointed out, expects the data to be in the BODY of the request. HTTP headers do have a limit on size - varies according to exact platform but see (eg) http://stackoverflow.com/questions/1097651/is-there-a-practical-http-header-length-limit – Tim Williams Jun 30 '15 at 00:52
  • @TimWilliams I agree but even when I'm sending through post, the same problem exists. The question is about how to pass the data which is more than 65535 characters, not about header or post – Linga Jun 30 '15 at 05:18
  • Which version of Excel are you using? The cutoff limit sounds too familiar (Excel 2003 has a max rows limit of 65,536) – gipadm Jul 01 '15 at 13:35
  • 1) You said the POST worked through PHP. Can you post the PHP code here? 2) Can you add this code at the top of this function and give us the output: `MessageBox len(poststring)` – steenbergh Jul 04 '15 at 07:06
  • Still not getting it done – Linga Jul 06 '15 at 07:27
  • change the user agent to ie – Jagadeesh Govindaraj Jul 06 '15 at 13:46
  • why? whats wrong with this – Linga Jul 06 '15 at 13:46
  • The address bar doesn’t shows any characters beyond 65,536 characters.but opera browser URL is completely visible in the address bar even at such a big range – Jagadeesh Govindaraj Jul 06 '15 at 13:48
  • so try to add opera as a user agent... – Jagadeesh Govindaraj Jul 06 '15 at 13:49

1 Answers1

3

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.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Can you explain `"id=" & String(66000,"x")` – Linga Jun 30 '15 at 06:53
  • That was just a dummy data string to pass for testing: a parameter named "id" with a 66k character value. – Tim Williams Jun 30 '15 at 20:02
  • Same problem.. The server didn't received anything via post. If it is <65535, i saw the post data in server. And also, the received full data when I was checking this in perl and php. So clearly, this is an VBA issue – Linga Jul 01 '15 at 10:22
  • 1
    If you monitor the request using something like Fiddler, what do you see? – Tim Williams Jul 01 '15 at 14:54
  • And it might be useful to say something about your server platform - what are you using? – Tim Williams Jul 01 '15 at 17:11