请教vb使用inet控件post数据的方法

DimInFileAsString="s:\voicetest\1.flac"DimfsAsIO.FileStream=NewIO.FileStream(InFile,I... Dim InFile As String = "s:\voicetest\1.flac"
Dim fs As IO.FileStream = New IO.FileStream(InFile, IO.FileMode.Open)
Dim voice() As Byte
ReDim voice(fs.Length)
fs.Read(voice, 0, voice.Length)
fs.Close()
Dim url As New Uri("http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=zh-CN&maxresults=1")
Dim Request As Net.HttpWebRequest
Request = Net.HttpWebRequest.Create(url)
Request.Method = "POST"
Request.ContentType = "audio/x-flac; rate=16000"
Request.ContentLength = voice.Length
Using Ws As IO.Stream = Request.GetRequestStream()
Ws.Write(voice, 0, voice.Length)
End Using
Using Response As Net.HttpWebResponse = Request.GetResponse()
Using ResponseStream As IO.Stream = Response.GetResponseStream()
Using ReadStream As IO.StreamReader = New IO.StreamReader(ResponseStream, System.Text.Encoding.UTF8)
TextBox1.Text = ReadStream.ReadToEnd
End Using
End Using
End Using

上面是我写的VB.NET方法,但我不知道怎么转成VB6.0,下面是我写的VB6.0但不能用。。。

private sub ToPost()
FileOutPath = "s:\voicetest\1.flac"
Dim MData() As Byte
ReDim MData(FileLen(FileOutPath) - 1)
Open FileOutPath For Binary As #1
Get #1, , MData
Close #1
Dim MUrl As String: MUrl = "http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=zh-CN&maxresults=1"
Dim MHreat As String: MHreat = "Content-Type: audio/x-flac; rate=16000;ContentLength :" + CStr(UBound(MData))
Inet1.Execute MUrl, "POST", MData, MHreat
end sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Select Case State
Case 12
Dim vtData As Variant '数据变量。
Dim strData As String: strData = ""
Dim bDone As Boolean: bDone = False

'取得第一块。
vtData = Inet1.GetChunk(1024, icString)
DoEvents
Do While Not bDone
strData = strData & vtData
DoEvents
'取得下一块。
vtData = Inet1.GetChunk(1024, icString)
If Len(vtData) = 0 Then
bDone = True
End If
Loop

MsgBox strData
End Select
End Sub
'VB6.0调试情况,state只出现过一次是8,然后就没有反应了。。。没有12
展开
 我来答
peter987662
2013-08-21 · TA获得超过1330个赞
知道小有建树答主
回答量:1117
采纳率:0%
帮助的人:1197万
展开全部

何必如此复杂?

Private Sub Command1_Click() 
Dim myurl As String, send_data As String, myhead As String 
myurl = "网址" 
send_data = "数据"
my_head = "Content-Type: application/x-www-form-urlencoded" 
Inet1.Execute myurl, "POST", send_data, myhead 
End Sub
更多追问追答
追问
问题是我post的是一个音乐文件的byte数组,然后还要读取返回值

上面的那个谷歌语音识别API,post一个flac文件,然后返回识别结果。。。

你的回复我不知道在那里读取识别结果
追答
漏了

还要
do while inet1.stillExecuting
doEvents
loop

之后就在要inet的changed事件里面判断 state = 12,来处理返回的数据
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式