Excel VBA WinHttp and how to submit a form with hidden fields

frigorific

New Member
Joined
Jan 7, 2010
Messages
1
Hi all, a tough one I'm struggling with, for a kind soul Excel VBA guru if there is one reading!

I'm using WinHttp to access from Excel VBA an URL, say "http://server/application?id=abc".

When I open this URL from Explorer, I get an HTML table with lots of info. The idea is to parse the table contents and fill some cells in my spreadsheet with the values received.

However when I try from Excel VBA with code like this:


Dim ht As New WinHttp.WinHttpRequest
ht.Open "POST", "http://server/application?id=abc", False
ht.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
ht.SetRequestHeader "Content-Type", "multipart/form-data; "
ht.Send
</PRE>

I obtain the following ht.ResponseText:


[script language="javascript" type="">
function submitForm() {
document.form1.submit();
}
[/script>
[html>
[body bgcolor="#FFFFFF" ******="submitForm()">
[font size="20" color="blue">Loading. Please wait.</font>
[form NAME="form1" ACTION="dispatch" METHOD="post">
[INPUT TYPE="hidden" name="action" value="response">
[INPUT TYPE="hidden" name="user_id" value="user">
[/FORM>
[/body>
[/html>
</PRE>

So it looks like it sets a couple of hidden parameters on a form and then submits itself upon load.

I've tried various things to no avail, for example adding those hidden fields like this:


Dim login As String
login = "action=response&user_id=user"
...
ht.Send login
</PRE>

But it doesn't do what I want it to do, which is to submit the form and present the response.

So my question is: How can I construct the WinHttp send request so that I obtain the response from the submitted form, and not the form itself?

My brain is hurting now so if anyone has any pointers on how to do this, it'll be most appreciated! Thanks in advance.

 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Shouldn't it be URL Encoded? Not multipart/form-data. Or does it matter? I am not a web developer by any stretch. It's going to be difficult to help you without the URL to work with. Can you find a suitable comparison from a publically available web site?
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,765
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top