在VB中,post和get提交数据有了两种方法实现,一个是inet控件,二是不用控件,用XMLHTTP组件
注意:
GET需要的参数有:URL(网址)
返回的是该URL源码
POST需要的参数有,URL(网址)、Data(发送的数据)、[有时候还需要修改数据包的头的参数,例如Content-Type、Referer等]
返回的是数据包发送的结果
【inet控件的GET】
多数情况下需要把接收的数据转换一下,否则汉字会变成乱码,转换过程是这样的,将接收二进制数据存入到二进制数组b(),再将b()转换成字符串,本文用Utf8ToUnicode函数实现二进制数组转换成字符串。
如果接收数据用Utf8ToUnicode转换后还有乱码,那么直接用ReData=Inet1.GetChunk(0, icString)用就行了。Utf8ToUnicode函数会在本文最后给出。
1、Inet1.OpenURL方法实现GET
Function InetGET(URL As String) As String
Dim b() As Byte
b = Inet1.OpenURL(URL, icByteArray)
InetGET = Utf8ToUnicode(b)
End Function
2、Inet1.Execute方法实现GET
首先说一下格式:
Inet1.Execute "这里是提交的url", "方式,POST或GET", "这里是提交的参数", "数据包的头"
Function InetGET(URL As String) As String
Inet1.Execute URL, "GET"
Do While Inet1.StillExecuting
DoEvents
Loop
Dim b() As Byte
b = Inet1.GetChunk(0, icByteArray)
InetGET = Utf8ToUnicode(b)
End Function
【inet控件的POST】
Function InetPOST(URL As String, Data As String) As String
Inet1.Execute URL, "POST", _
Data, _
"Content-Type: application/x-www-form-urlencoded"
Do While Inet1.StillExecuting
DoEvents
Loop
Dim b() As Byte
b = Inet1.GetChunk(0, icByteArray)
InetPOST = Utf8ToUnicode(b)
End Function
【XMLHttp组件的GET】
Function XMLHttpGET(URL As String) As String
Dim h As Object
Set h = CreateObject("Microsoft.XMLHTTP")
h.Open "GET", url, True
h.send ""
Do While h.ReadyState <> 4 '循环防止卡死
DoEvents
Loop
If h.ReadyState = 4 Then XMLHttpGET = StrConv(h.Responsebody, vbUnicode) '当h.ReadyState=4时说明源码加载完毕
End Function
【XMLHttp组件的POST】
Function XMLHttpPOST(ByVal url As String, ByVal PostData As String) As String
Set XML = CreateObject("Microsoft.XMLHTTP")
With XML
.Open "POST", url, False
.setRequestHeader "Accept", "*/*"
.setRequestHeader "Accept-Language", "zh-cn"
.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Referer", ""
.setRequestHeader "Content-Length", Len(PostData)
.setRequestHeader "Connection", "Keep-Alive"
.setRequestHeader "Cache-Control", "no-cache"
.Send (PostData)
Do Until .ReadyState = 4
DoEvents
Loop
XMLHttpPOST = .responseText
End With
Set XML = Nothing
End Function
表单提交中Get和Post方式的区别_计算机软件及应用_IT/计算机_专业资料。表单...仍然以新闻站 点为例,读者对文章的注解应该通过 POST 请求实现,因为在注解提交...
http请求(get和post)的java实现_计算机软件及应用_IT/计算机_专业资料。package...billNo=010027078277&Key=VbmYfP6SeO6apmRAmgg67Q=="; String ret =Http...
HTTP请求:GET与POST方法的区别_计算机软件及应用_IT/计算机_专业资料。HTTP ... C++实现Http Post请求 5页 免费 http里get 与post区别 1页 免费...
http中get和post的区别_计算机软件及应用_IT/计算机_专业资料。http 中 get 和 post 的区别: 1. get 从服务器上获取数据,post 是向服务器传送数据 2. 在...
具体的全局事件请参考 API 文档。 好了,下面开始说 jQuery 里面功能最强的 ...简单易用的高层实现见 $.get, $.post 等。 $.ajax() 返回其创建的 ...
一、get()和 post()基本区别 get()和 post()基本区别 1.get 是把参数数据队列加到提交表单的 ACTION 属性所指的 URL 中, 值和表 单内各个字段一一对应,...
jquery的get,post和ajax方法的使用_计算机软件及应用_IT/计算机_专业资料。使用Jquery 实现ajax 简单介绍,关键代码。jquery的get,post和ajax方法的使用 分类: ...
asp中get和post的差别_IT/计算机_专业资料。在Form里面,可以使用post也可以使用get。它们都是method的合法取值。但是,post和get方法在使用上至少有两点不同: 1、...
Ajax中的get和post两种请求方式的用法_IT/计算机_专业资料。Ajax中的get和post两种请求方式的用法Ajax中我们经常用到get和post请求.那么什么时候用get请求,什么时候...
ajax中get和post提交_计算机软件及应用_IT/计算机_专业资料。2010-08-06 15:...()方式对url实现两次编码,因为表单数据有中文字符,发送到Action中以后还要对其...
热门文档