采用POST还是GET方式提交CGI
编号:QA002208
建立日期: 1999年12月9日 最后修改日期:1999年12月9日
所属类别:
Liu Zhe:
操作系统: Windows NT Workstation 4.0
编程工具: Visual Basic 6.0 Enterprise
问题: 我希望使用VB 的Internet Transfer Control实现访问搜索引擎,比如说ALLTHEWEB。问题发生在我使用Execute方法和POST向CGI递交数据,我是采用VB帮助文档里的办法操作的:
举例讲,我希望在www.alltheweb.com中查询gis, 相应的地址加参数为
http://www.alltheweb.com/cgi-bin/asearch?type=all&query=gis
我认为http://www.alltheweb.com/cgi-bin/asearch就是URL,type=all&query=gis是向CGI传的参数。
Private Sub Form_Load()
Dim strURL As String, strFormData As String
strURL = "http://www.alltheweb.com/cgi-bin/asearch"
strFormData = "type=all&query=gis"
Inet1.Execute strURL, "post", strFormData
end sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim vtData As Variant ' Data variable.
Select Case State
Case icResponseCompleted
vtData = Inet1.GetChunk(1024, icString)
Do While LenB(vtData) > 0
vtData = vtData + Inet1.GetChunk(1024, icString)
Loop
End Select
Text1.Text = vtData
End Sub
注:ITC控件已正确放置。
但是ITC控件返回的结果指示CGI的参数有错。因此也无法得到所需结果。 请告诉我一个解决办法,谢谢。
回答:
你说的这个地址是采用GET方式提交的,而不是采用POST方式提交。两者的区别在于:GET方式所有参数会出现到URL中,而POST方式的参数不会出现在URL中。你也可以查看HTML页码,查找其中的<FORM>标记,看是POST方式,还是GET方式。如果方式错了,有的CGI程序将无法获得参数。正确的调用方式为:
Inet1.Execute"http://www.alltheweb.com/cgi-bin/asearch?type=all&query=gis", _
"GET", strFormData
此问题由李海回答。
| |
|
|
| |
|
|