模拟表单

HttpClient有个FormData属性,这是一个字典,用于添加需要向服务器提交的表单数据。

一个例子

1、服务端项目的HttpRequest事件代码:

Select Case e.Path
    Case "AddNew.htm"
        Dim nms() As String =
{"
产品","客户","数量","单价","日期"}
        For  Each nm As String In nms
            If e.PostValues.ContainsKey(nm) = False Then
                e.AppendCookie("error",
"
请输入" & nm)
                Return
            End If
        Next
        Dim dr As DataRow = DataTables(
"
订单").AddNew()
        For  Each nm As String In nms
           
dr(nm) = e.PostValues(nm)
        Next
        dr.Save()
        e.WriteString(dr("_Identify")) '返回主键列的值给客户端
        dr.Remove()
'移除此行

End
Select

2、客户端项目可以通过以下代码增加订单,并获得新增订单的主键:

Dim hc As New HttpClient("http://127.0.0.1/AddNew.htm")
hc
.FormData.Add("产品","PD01")
hc
.FormData.Add("客户","CS01")
hc.FormData.Add("数量","100")
hc
.FormData.Add("单价","98")
hc
.FormData.Add("日期",Date.Today)
Dim
ret As String = hc.getData()
If
hc.rCookies.ContainsKey("error") Then
    MessageBox.Show(hc.rCookies("error"),
"
提示", MessageBoxButtons.OK ,MessageBoxIcon.Warning)
Else

    MessageBox.Show("增加行成功,新增行的主键为:" & ret)

End
If

 


本页地址:http://www.foxtable.com/mobilehelp/topics/0159.htm