我一直在研究这个问题大约一个月了。我在POST方法上看到过几十个网页,我无法弄清楚如何使用它。
我有这个HTML表单,可以将数据和文件发布到网站上。这个HTML表单效果很好:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sample Post Request</title>
</head>
<body>
<form action="https://xxx.xxx.com//trackit/file/upload"
method="post" enctype="multipart/form-data">
<div>
<p>
File Name<select name="name">
<option value="" disabled="disabled" selected="selected">Select file name</option>
<option value="Customer">Customer</option>
<option value="Shipment">Shipment</option>
</select>
</p>
<p>
File Date:<input type="text" name="date"> format : YYYYMMDD
</p>
<p>
Upload File: <input type="file" name="file" />
</p>
</div>
<input type="submit" value="Upload It" />
</form>
</body>
</html>
但是,我正在尝试自动执行此操作,因此我不必使用该表单。以下是我到目前为止的情况:
OPTION EXPLICIT
DIM sFile, sURL, sDate, sName, objStream
'File Type
sName = "Shipment"
'File Date YYYYMMDD
sDate = "20150717"
' File we are uploading
sFile = "C:\shipment.txt"
sBoundary = "|-O-|"
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeText
objStream.Mode = adModeReadWrite
objStream.Open
objStream.LoadFromFile sFile
'Sending the data over HTTP Post
Set objHttp = CreateObject("MSXML2.XMLHTTP")
objHttp.Open "POST", "https://xxx.xxx.com//trackit/file/upload", False
objHttp.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" + sBoundary
objHttp.Send "name=" + sName
objHttp.Send "date=" + sDate
任何帮助将不胜感激。