【问题标题】:VB6 To send a Form PostVB6 发送表单帖子
【发布时间】:2013-03-16 14:28:15
【问题描述】:

这是我正在使用的代码:

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 中的所有内容。 如果我添加一个查询字符串对象,我可以看到每个对象。 我看不到表单对象。

【问题讨论】:

  • 您是否完全按照输出粘贴响应?如图所示,它似乎完全缺少空格。它还缺少表单的开头 &lt; 字符。
  • 为什么要向服务器发送 HTML?这不是表单帖子的工作方式。
  • @Bob77 哈。好点子。我太着迷于查看响应,以至于我从未真正查看过请求。
  • 我不想在这个项目上使用 XML。这应该有效吗?
  • 我想在服务器和在客户位置运行的程序之间交换信息。这有更好的办法吗?我对想法持开放态度。该程序需要通过几乎所有操作来评估服务器。我需要一个快速的通信系统,因为服务器将访问 SQL 服务器并发回信息。由于字符限制,我不想使用 XML。我正在研究的另一种方法是来回使用分隔文本文件。

标签: vb6 form-post


【解决方案1】:

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

strIDJob = "34"
strAuthString = "supertest"

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

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

(使用 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 = supertest

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-09
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多