0

这是我正在使用的代码:

Dim httpReq As New WinHttp.WinHttpRequest
Dim strLineOut As String
Dim strReturn As String
Dim strStatus As String

lblResponse1.Caption = ""
DoEvents
strLineOut = "<form name=""form1"" method=""post"" enctype=""multipart/form-data"">" & vbCrLf
strLineOut = strLineOut & "  <input name=""hdntype"" type=""hidden"" id=""hnd1"" value=""1"">" & vbCrLf
strLineOut = strLineOut & "  <input name=""hnd1"" type=""hidden"" id=""hnd1"" value=""Value1"">" & vbCrLf
strLineOut = strLineOut & "  <input name=""hdn2"" type=""hidden"" id=""hdn2"" value=""Value2"">" & vbCrLf
strLineOut = strLineOut & "  <input type=""submit"" name=""Submit"" value=""Submit"">" & vbCrLf
strLineOut = strLineOut & "</form>" & vbCrLf

httpReq.Open "POST", "http://www.XXXX.com/XMLProjects/vb6test/form_post.asp", False
httpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'text/xml
'application/x-www-form-urlencoded
'httpReq.StatusText
'httpReq.Status
'httpReq.SetRequestHeader "Content-Length", Len(strLineOut)
httpReq.Send (strLineOut)
strStatus = httpReq.StatusText
strReturn = httpReq.ResponseText
Debug.Print strReturn & vbCrLf & strStatus
lblResponse1.Caption = strReturn & vbCrLf & strStatus
Set httpReq = Nothing

捕获表单的asp似乎无法识别表单。它看到一个包含一个项目的表单。asp中的catch代码是:

Response.Write Request.Form("hdntype") 
Response.Write "the form object is " & Request.Form.Item(1) & vbCrLf

来自asp的响应是:

the form object is "form1"method="post"enctype="multipart/form-data">
<inputname="hdntype"type="hidden"id="hnd1"value="1">
<inputname="hnd1"type="hidden"id="hnd1"value="Nick">
<inputname="hdn2"type="hidden"id="hdn2"value="Arnone">
<inputtype="submit"name="Submit"value="Submit"></form>

它看不到项目 hdntype 或表单中的任何其他项目。它看到 1 个项目,整个表单。

如果我执行 Request.TotalBytes,我可以在 asp 中看到所有内容。如果我添加一个查询字符串对象,我可以看到每个对象。我看不到表单对象。

4

1 回答 1

0

在 VB6 中,如果您发送这样的数据:

strIDJob = "34"
strAuthString = "supertest"

DataToPost = ""
DataToPost = DataToPost & "IDJob=" & strIDJob & "&"
DataToPost = DataToPost & "AUTH=" & strAuthString & "&"

(我使用 CreateObject("Msxml2.XMLHTTP.6.0") 组件将其发送到 ASP 页面)

(使用 POST 发送,仅包含此标头:“application/x-www-form-urlencoded”)

然后,您可以使用下面的代码(在 ASP 中)一一检索每个项目:

IDJob = Request.Form.Item(1)   'here is the core point of this post. This is the line that matters
AUTH = Request.Form.Item(2)   'here is the core point of this post. This is the line that matters

response.write "IDJob = " & IDJob & "<BR>"
response.write "AUTH = " & AUTH & "<BR>"
Response.End

asp中的这段代码产生以下返回/输出:

IDJob = 34
AUTH = 超级测试

于 2019-12-09T21:30:04.787 回答