来自 Visual Basic 6 的 HTTP 发布/上传 [英] HTTP Post/Upload From Visual Basic 6

查看:35
本文介绍了来自 Visual Basic 6 的 HTTP 发布/上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Basic 6 并希望通过发送自定义输入字段和 PDF 文件来向服务器(它运行 Java 代码)执行 HTTP 发布.PDF 文件必须是 base 64 位编码,或者在上传文件时使用 HTTP post 在 Internet 上工作的正常方式.基本上我只想从我的 Visual Basic 6 程序上传一个文件.

I'm using Visual Basic 6 and want to do an HTTP post to a server (it runs Java code) by sending a custom input field along with a PDF file. the PDF file would have to be base 64 bit encoded or use the normal way that HTTP post work over the Internet when uploading a file. Basically I just want to upload a file from my Visual Basic 6 program.

我该怎么做?有示例源代码吗?

How do I do this? Any example source code?

推荐答案

假设您知道如何将 PDF 加载到字节数组中,您必须对其进行 Base64 编码,然后使用 MIME 多部分编码将其发布到服务器.

Assuming you know how to load the PDF in to a byte array you've got to get it Base64 encoded and then post that to server using MIME multipart encoding.

您可以利用 MSXML 库功能来执行 Base64 编码.请参阅此链接了解详情.

You can utilise the MSXML libraries ability to perform Base64 encoding. See this link for details.

将 PDF 作为 Bas64 字符串后,您需要将其打包为 MIME 多部分.您可以使用 MSXML 中的 XMLHTTP 对象为您执行该发布:-

Once you have the PDF as a Bas64 string you need to package that as MIME multipart. You can use XMLHTTP object from MSXML to perform that posting for you:-

sEntityBody = "----boundary" & vbCrLf
sEntityBody = sEntityBody & "Content-Disposition: form-data; name=fileInputElementName; filename=""" + sFileName + """" & vbCrLf
sEntityBody = sEntityBody & "Content-Transfer-Encoding: base64" & vbCrLf
sEntityBody = sEntityBody & "Content-Type: application/pdf" &  vbCrLf & vbCrLf
sEntityBody = sEntityBody & sPDFBase64 & vbCrLf
sEntityBody = sEntityBody & "-----boundary--" & vbCrLf & vbCrLf

Set xhr = New MSXML2.XMLHTTP30
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=-----boundary")
xhr.Open "POST", sUrl, False
xhr.send sEntityBody

也许不优雅或不高效,但它应该可以工作.

Perhaps not elegant or efficient but it should it work.

这篇关于来自 Visual Basic 6 的 HTTP 发布/上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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