Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBA code snippet for HTTP POST x-www-form-urlencoded?

1,138 views
Skip to first unread message

Stephane Barizien

unread,
Oct 3, 2000, 3:00:00 AM10/3/00
to
I want to script a query that uses an HTTP form with the POST method and
the Content-Type application/x-www-form-urlencoded from a Word97 macro.

Basically I want to retrieve the HTML output a CGI produces when a user
enters some value into the search field of a form that uses POST.

I know the basics of POST and x-www-form-urlencoded and all that, and I
have a working VBA code snippet (used WinInet.dll) to perform an HTTP
GET but I'd like something I'd just have to copy/paste into my Word
macro, instead of having to write it from scratch...

TIA

Klemens Schmid

unread,
Oct 9, 2000, 3:00:00 AM10/9/00
to
If you know the basics why do you not write it? I had to read the
basics first. Here is my sample: www.schmidks.de > My Tools > "Http
Post ...". It uses the XMLHttp object rather than WinInet.dll.
Regards,
Klemens

In article <39D9DDDC...@ocegr.fr>,


Sent via Deja.com http://www.deja.com/
Before you buy.

Stephane Barizien

unread,
Oct 17, 2000, 3:00:00 AM10/17/00
to Klemens Schmid
Klemens Schmid wrote:
>
> If you know the basics why do you not write it? I had to read the

Maybe just 'cos I'm lazy ;-)

Actually I was unsure I would be able to play the stdout/stdin game that
POST requires with WinInet from VBA (probably using InternetWriteFile
would have done it)

> basics first. Here is my sample: www.schmidks.de > My Tools > "Http
> Post ...". It uses the XMLHttp object rather than WinInet.dll.

Seems to yield far simpler code. Hope this can work from Word 97's VBA
-- I'm not using real VB, as you are.

Thx for the code.

Regards,

Stephane.

Stephane Barizien

unread,
Oct 17, 2000, 3:00:00 AM10/17/00
to Klemens Schmid
Klemens Schmid wrote:
>
> If you know the basics why do you not write it? I had to read the
> basics first. Here is my sample: www.schmidks.de > My Tools > "Http
> Post ...". It uses the XMLHttp object rather than WinInet.dll.
> Regards,
> Klemens

As I expected, the VB->VBA translation is not without pain. I'm
currently with:

Sub HTTPPost()

Dim strText As String
Dim strBody As String
Dim strFileName As String
Dim oHttp As Object

' XMLHTTP26 fails, this works (version? I have IE5.5 installed
Set oHttp = CreateObject("Microsoft.XMLHTTP")

oHttp.Open "POST", "http://userwebs.ocegr.fr/~sba/cgi-bin/post-query",
False
oHttp.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
strBody = "INITIAL=on&PATTERN=sba&SITE=0&x=28&y=12"
'the send method fails consistenly with error 0x80004005
oHttp.send strBody
Debug.Print oHttp.responseText

End Sub

Any clue?

TIA

0 new messages