VB调用VB脚本VBS向Http请求的三种方式
VB代码
第一步,创建脚本对象,读出 VBStest.txt 文件
Private myScript As Object Private Sub Form_Load() Call m_Initialize End Sub Public Sub m_Initialize() Dim strScriptFile As String Dim strScript As String Dim intFile As Integer intFile = FreeFile strScriptFile = App.Path & "\Script\VBStest.txt" If Dir(App.Path & "\Script\VBStest.txt") <> "" Then Open strScriptFile For Binary As #intFile strScript = Input(LOF(intFile), intFile) Close intFile Set myScript = CreateObject("ScriptControl") myScript.Language = "VBScript" 'myScript.timeout = 1000 myScript.AddCode strScript End If End Sub
第二步 脚本调用的方法
Public Function m_FCustom1(ByVal str调用名称 As String, ByVal str服务器参数 As String, ByRef str返回值 As String) As Boolean On Error GoTo ErrTrap Dim strA As String str返回值 = myScript.Run(str调用名称, str服务器参数) 'm_FCustom1 = True Exit Function ErrTrap: MsgBox ("出错!" & CStr(Err) & " " & Error(Err)) On Error GoTo 0 End Function
第一种 Post方式
Private Sub Command3_Click() Dim strA As String Call m_FCustom1("m_Post", "m_Post 11111111", strA) MsgBox ("返回值!" & strA) End Sub
第二种 Get 方式
Private Sub Command4_Click() Dim strA As String Call m_FCustom1("m_Get", "m_Get 222222222", strA) MsgBox ("返回值!" & strA) End Sub
第三种 Json 方式
Private Sub Command1_Click() Dim strA As String Call m_FCustom1("m_PostTest", "m_Post 接口调试", strA) MsgBox ("返回值!" & strA) End Sub
VB脚本代码 VBStest.txt
Function m_Get(strTelNumber) Dim strA Dim http Dim strUrl strUrl="http://localhost/callcenter2/VBStest.php?AAAA=1111" Set http = CreateObject("Msxml2.ServerXMLHTTP") 'strA = http.open("GET", "http://www.baidu.com", False) strA = http.open("GET", strUrl, False) http.send MsgBox http.Status MsgBox http.responsetext m_Get = http.responsetext End Function Function m_Post(strTelNumber) Dim strA Dim http Dim strUrl strUrl="http://localhost/callcenter2/VBStest.php" set Http=createobject("MSXML2.XMLHTTP") 'strA = http.open("POST", "http://www.baidu.com", False) strA = http.open("POST", strUrl, False) http.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded" http.Send "Text1=1AA&Text2=2BBBBB" MsgBox http.Status MsgBox http.responsetext m_Post = http.responsetext End Function 'Jost方式 Function m_PostTest(strTelNumber) Dim strA Dim http Dim strUrl strUrl="http://211.140.196.159:9979/hlbr/api/callcenter/advisory" set Http=createobject("MSXML2.XMLHTTP") 'strA = http.open("POST", "http://www.baidu.com", False) strA = http.open("POST", strUrl, False) http.setRequestHeader "CONTENT-TYPE","application/json" http.Send "{'id':'1'}" MsgBox http.Status MsgBox http.responsetext
m_Post = http.responsetext End Function
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2010-09-03 PHP获取随机数
2010-09-03 PHP 获取时间差