VB6 http post 发送与返回内容处理

前端之家收集整理的这篇文章主要介绍了VB6 http post 发送与返回内容处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

今天帮同事做另一家公司的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


效果



VB6比较老了,没有Java和C#那么完备,也没什么插件可以实现特定功能,但任然可以用原始的语句写出很多功能

猜你在找的VB相关文章