VB6 http post 发送与返回内容处理
发布时间:2020-12-17 07:42:48 所属栏目:百科 来源:网络整理
导读:今天帮同事做另一家公司的Web系统数据对接,我方发送请求,对方返回一些数据,用的是客户端用的是VB6,代码记录如下: Dim postData As StringDim url As String url = "http://111.11.11.11/services/getQuickInfoService"postData = TextContent.Text'---
今天帮同事做另一家公司的Web系统数据对接,我方发送请求,对方返回一些数据,用的是客户端用的是VB6,代码记录如下:
Dim postData As String Dim url As String url = "http://111.11.11.11/services/getQuickInfoService" postData = TextContent.Text '--- post Dim HttpClient As Object Set HttpClient = CreateObject("Microsoft.XMLHTTP") HttpClient.Open "POST",url,False HttpClient.setRequestHeader "Content-Type","text/xml; charset=UTF-8" HttpClient.Send pvToByteArray(postData) Do While HttpClient.readyState <> 4 DoEvents Loop TextResponse.Text = HttpClient.responseText MsgBox "发送完毕" 下面是发送内容的编码部分:
' 下面是两个转换函数 Private Function pvToByteArray(sText As String) As Byte() pvToByteArray = GB2312ToUTF8(sText) End Function Public Function GB2312ToUTF8(strIn As String,Optional ByVal ReturnValueType As VbVarType = vbString) As Variant Dim adoStream As Object Set adoStream = CreateObject("ADODB.Stream") adoStream.Charset = "utf-8" adoStream.Type = 2 'adTypeText adoStream.Open adoStream.WriteText strIn adoStream.Position = 0 adoStream.Type = 1 'adTypeBinary GB2312ToUTF8 = adoStream.Read() adoStream.Close If ReturnValueType = vbString Then GB2312ToUTF8 = Mid(GB2312ToUTF8,1) End Function
效果:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |