You need to enable JavaScript to run this app. 如何修改VB6 POST RESTful接口代码以添加指定body参数
优惠活动
大模型
产品
解决方案
定价
更多

如何修改VB6 POST RESTful接口代码以添加指定body参数

修改后可直接运行的完整代码

Dim sUrl As String
Dim response As String
Dim xmlhttp
Dim postBody As String

' 接口地址
sUrl = "http://my.domain.com/service/operation/param"
' 构造x-www-form-urlencoded格式的请求体
postBody = "number=123456&first_name=james"

Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", sUrl, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
' 发送时传入请求体
xmlhttp.send postBody

' 获取响应结果
response = xmlhttp.responseText

Set xmlhttp = Nothing

修改说明

  • 修正原有代码语法错误:字符串变量sUrl为基础类型变量,赋值不需要加Set关键字;删除重复的response变量声明,避免编译报错
  • 新增postBody变量拼接请求参数,application/x-www-form-urlencoded格式要求参数用&拼接,键值对用=连接
  • 将构造完成的postBody作为参数传入send方法,即可完成带请求体的POST请求
  • 如果后续参数包含中文、空格或特殊符号,需要先对参数值做URL编码后再拼接,避免传参异常

内容的提问来源于stack exchange,提问作者Tobyy Damian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 01:42:03