从 VBA (WinHTTP) 通过 HTTP 上传文件
我正在尝试从 VBA 中以编程方式 (HTTP) 上传二进制文件。我打算在服务器上放置一个 ASPX 页面来接受文件和某些附加参数。
我知道有很多好的方法可以做到这一点(例如使用 Web 服务而不是 aspx),但我的限制是它必须在 VBA 中运行(在 Excel 文件中),并且我无法在客户端上安装任何其他组件。
所以我想我会使用 WinHTTP,并且我找到了几个发布表单数据的示例,但不发布二进制文件。我可能需要对文件内容进行 Base64 处理?
所以我的问题是:
- 我是否需要手动进行编码,或者我可以让 WinHTTP 这样做吗?
- 有没有比 WinHTTP 更好的实用程序? (请记住,我不想安装任何其他软件,它必须随 WinXP Pro、Office 2007 或 .NET 框架一起提供,例如)
- 是否有更好的方法,例如使用 ASP.NET Web 服务?
谢谢,奇科多罗
I'm trying to (HTTP) upload a binary file programmatically from within VBA. I intend to put an ASPX page on the server to accept the file and certain additional parameters.
I know there are lots of nice ways to do that (e.g. use web service instead of aspx), but my constraint is that it must run in VBA (in an excel file), and that I cannot install any additional components on the client.
So I guess I'll use WinHTTP, and I've found several examples to post form data, but not to post a binary file. I probably need to base64 the file contents?
So my questions are:
- Do I need to do the encoding manually or can I make WinHTTP do that?
- Is there a better utility to use than WinHTTP? (Remember I don't want to install any additional software, it must be shipped with WinXP Pro, Office 2007 or a .NET framework, e.g.)
- Is there a better way to go, e.g. using ASP.NET web services?
Thx, chiccodoro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能使用base64,但通常编写二进制文件更容易。
您必须跨越的障碍是构建有效的多参数/表单 POST。使用 WinHTTP 完全可以做到这一点,虽然我已经很多年没有这样做了,也没有提供示例代码的工具,但这并不简单。
您可以参考以下文章,了解如何使用 C# HttpWebRequest 执行此操作的示例。当然,WinHTTP api 有点不同,但从文章中可以看出的要点是 POST 正文的结构。
通常我会提供示例代码,但正如我所说,我现在没有设置任何石器时代工具;-) 。
华泰
You may use base64 but typically writing binary is easier.
The hurdle you have to leap is constructing a valid multi-par/form POST. This is completely possible using WinHTTP, although I have not done it in years and am not tooled to provide sample code, it is not trivial.
You can reference the following articles for examples of how to do this with C# HttpWebRequest. The WinHTTP api is a bit different of course but the salient points to take away from the articles is the structure of the POST body.
Typically I provide sample code, but as I said, I do not have any stone-age tools set up right now ;-).
HTH