我一直在尝试使用 multipart/form-data 将数据发布到服务器,但是服务器似乎没有收到任何内容。
VB代码
' create a boundary consisting of a random string
strBoundary = RandomAlphaNumString(32)
strBody = "--" & strBoundary & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""test1""" & vbCrLf & vbCrLf & STRING
strBody = strBody & vbCrLf & "--" & strBoundary & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""data""" & vbCrLf & vbCrLf & data
strBody = strBody & vbCrLf & "--" & strBoundary & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""data2""" & vbCrLf & vbCrLf & data2
strBody = strBody & vbCrLf & "--" & strBoundary & vbCrLf
strBody = strBody & "Content-Disposition: form-data; name=""data3""" & vbCrLf & vbCrLf & data3
strBody = strBody & vbCrLf & "--" & strBoundary & "--"
' Content-Length
sHttpLength = Len(strBody)
Set WinHttpReq = New WinHttpRequest
strURL = "https://" & HOST & URL ' directed to test.php
hostHeader = HOST & vbCrLf
contentTypeHeader = "multipart/form-data; boundary=" & strBoundary & vbCrLf
contentLengthHeader = sHttpLength & vbCrLf & vbCrLf
WinHttpReq.Open "POST", strURL, False 'Open a Http connection
WinHttpReq.SetRequestHeader "HOST", hostHeader
WinHttpReq.SetRequestHeader "Content-Type", contentTypeHeader
WinHttpReq.SetRequestHeader "Content-Length", contentLengthHeader
WinHttpReq.Send strBody ' Send Post messages
服务器正在接收请求,因为它将数据发送回 vb 应用程序,但它无法识别已发布的对
例如
$postedVal = isset($_POST["test1"]) ? $_POST["test1"] : '';
这返回 '' 表明数据没有被正确接收。
有什么我没有看到的重大缺陷吗?
任何建议都会很棒。