如何使用VBA通过HTTP发布zip文件? [英] How do I upload a zip file via HTTP post using VBA?

查看:302
本文介绍了如何使用VBA通过HTTP发布zip文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被其他人以某种形式问了很多次,但是大部分仍然没有得到回答,或者给出的答案是Use C#,duh!,顺便说一句,这是一个没有答案的答案。 ; - )



我想通过VBA将zip文件上传到Web服务器。服务器端代码已经存在,运行良好;它接受通过手动形式上传的zip文件,并与zip文件的内容做一些事情。



理论是,我打算把zip文件的二进制内容转换成一个HTTP请求字符串,并使用WinHTTP库中的某些方法将其发送到服务器。如果一切顺利的话,服务器端脚本(在Perl中)应该无法判断文件是来自VBA还是浏览器,并继续正常工作。



然而,将zip文件转换为HTTP请求字符串似乎不是非常简单的。

在线搜索似乎表明存在3种常见策略:方法1:WinHTTP和手动编码二进制到HTTP请求字符串




  • 涉及以二进制模式打开文件并手动应用一些编码voodoo来更改二进制流到一个HTTP请求字符串,并使用WinHTTP的方式发送它。方法2:WinHTTP / strong>




    • 涉及使用ADODB.Stream。方法3:通过SendKeys自动执行IE浏览器

      $ b

    • $ b

      • 只有一个词来形容这个黑客:Yuck!如果还没有,可能会在未来的IE版本中打破。少于十行的代码。 安全风险



      我倾向于方法2 代码很少,例子很少,而且没有把握。大多数代码示例是不完整的,经常有评论说,他们不工作。这个方法是否真的有效?



      方法1 方法3 请不要! (而是使用C#,如果涉及到这一点,爱C#,只是需求只允许VBA)

      任何人都有如何完成这个任务的很好的例子吗?

      解决方案

      在使用上述所有方法进行了大量实验之后,我使用了几乎相当于方法1 - 我使用 http:// www。 motobit.com/tips/detpg_post-binary-data-url/ ,但有以下分配:

       设置http = CreateObject(WinHttp.WinHttprequest.5.1)

      ...而不是建议的该代码(代码是有点老人,我认为)。这并不完美,但是,例如,我一直无法使用旧的Windows XP机器(在Win7上工作正常)。


      This question has been asked many times by others in some form or another but most remained unanswered or the given answer is "Use C#, duh!", which incidentally, is a non-answer. ;-)

      I want to upload a zip file to a web server via VBA. The server side code already exists and works well; it accepts zip files via manual form upload and does something with the contents of the zip file.

      The theory is, I plan to transform the binary contents of the zip file into a HTTP request string and send it to the server using some methods from the WinHTTP library. If everything goes well the server side script (in Perl) shouldn't be able to tell whether the file came from VBA or a browser and continue working normally.

      However, transmogrifying the zip file to a HTTP request string doesn't seem to be very straight forward.

      Searching online seems to indicate there exists 3 common strategies:

      Method 1: WinHTTP and manual encoding of binary to HTTP request string

      • Involves opening the file in binary mode and manually applying some encoding voodoo to change the binary stream into a HTTP request string and send it on its way using WinHTTP. Scary amount of code.

      Method 2: WinHTTP

      • Involves using the ADODB.Stream. Less than ten lines of code.

      Method 3: Automate IE via SendKeys

      • There's only one word to describe this hack : Yuck! And probably will break in future version of IE, if not already. Less than ten lines of code. Security risk.

      I leaning towards Method 2, however, documentation is thin, code examples rare, and there's no certainty that it works. Most code examples are incomplete and often have comments that say they don't work. Does this method actually work?

      Method 1 is next in line.

      Method 3 Please, no! (Rather use C# if it comes to that. Love C#, just the requirements only permit VBA)

      Anyone has any good examples on how to accomplish this task?

      解决方案

      After a horrific volume of experimentation with all your methods above (and more), I'm using what pretty much amounts to your "Method 1" - I'm using item (2) from http://www.motobit.com/tips/detpg_post-binary-data-url/, but with the following assignment:

       Set http = CreateObject("WinHttp.WinHttprequest.5.1")
      

      ... instead of the one suggested in that code (the code is a little elderly, I think). It is not perfect, though - for example, I've been so far unable to get it working on an old Windows XP machine I had (works ok on Win7).

      这篇关于如何使用VBA通过HTTP发布zip文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆