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:

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
L

Legacy 98055

Guest
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,709
Messages
5,597,693
Members
414,164
Latest member
ARTW

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
Top