VB6发送表格帖子

时间:2013-03-26 17:00:49

标签: vb6 form-post

以下是我正在使用的代码:

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中看到everythinhg。 如果我添加一个查询对象,我可以看到每个对象。 我看不到表格对象。

1 个答案:

答案 0 :(得分: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 =超级测试