简体   繁体   中英

VBA send XMLHttpRequest from Internet Explorer

tl;dr: How can one send a POST request in VBA by using an XMLHttpRequest within the Internet Explorer?


I'm about automating the use of page on the internet. The idea is to start from Excel to gather some data in a worksheet, then transfer these data to the internet page, click some buttons in the meantime, and thereafter work on manually.

I recorded the whole process when executed manually by the F12 Developer tools. By bringing the data into the textboxes of the internet page, some Javascript events take place which fire a POST request through XMLHttpRequest: 在此处输入图片说明

Now, by replicating the procedure described above in VBA (using getElementById , .click() , .value= and the like), it appears that the relevant events are not fired: no such POST request as shown above are sent to the server, and no additional masks open. This is why I wanted to omit the textbox-filling-and-clicking approach and simply replicate the POST request.

How can I do this from VBA by using the Internet Explorer?

Disclaimer: I'm aware how to send a POST request using MSXML2.serverXMLHTTP , which is described hundreds of times over the web. However, there it's always either-or: either use the Internet Explorer, or MSXML2.serverXMLHTTP . However, I need the request within the Internet Explorer.

These links looks promising | VB5 | C# | Navigate method, 4th argument | Another VB example using StrConv for byte array conversion | It looks like you simply use the Navigate method and simply data packed into a byte array for the fourth argument. One of the above links is old but the newer link looks very similar so I think the interface has not changed much.

Do please post feedback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM