用VB6来完成POST提交data字串
我用POST将参数值data字串{"pxh":"1","pfl":"3","pzl":"7246.1",...,"recipeWJJ1":"12.1"}提交,在网上测试成功,如下:因为实际使用中data字串是我用VB6从SQL数据库中读取拼接的,所以要用VB6来完成POST提交data字串,以下是我用VB6写的:
Dim Postdata As String
Const STR_BOUNDARY As String = "3fbd04f5-b1ed-4060-99b9-fca7ff59c113"
Set http = CreateObject("Microsoft.XMLHTTP") '创建请求对象
Url = "http://101.200.202.124/ext/station/scrw/saveData/" '设置POST请求的Url
http.Open "POST", Url, False '异步方式建立请求链接
http.setRequestHeader "token", "1201030104" '设置请求头
http.setRequestHeader "mixer", 57
http.setRequestHeader "no", 20201231-297
http.setRequestHeader "Content-Type", "form-data; boundary=" & STR_BOUNDARY '设置boundary
'封装POSTbody:(其中data是JSON格式字串{"pxh":"1","pfl":"3","pzl":"7246.1",...,"recipeWJJ1":"12.1"}
Postdata = "--" & STR_BOUNDARY & vbCrLf _
& "Content-Disposition: form-data; key=""data""" & "; value=" & data & vbCrLf _
& "--" & STR_BOUNDARY & "--"
http.Send (Postdata) '发送POST请求
但是请求后得到错误回复:
http.responseText "请求参数错误"
想请问高手,封装POSTbody中的"Content-Disposition: form-data; key=""data""" & "; value=" & data
我是根据网上测试界面写的,是不是有问题? 正确的应该怎么写? 请求赐教,谢谢!