如下代码,appid和key最好还是你自己注册一个
Dim q As String = "Use pixels to express measurements for padding and margins."
Dim from As String = "en"
Dim [To] As String = "zh"
Dim appid As String = "20160221000012908"
Dim salt As String = Rand.Next(1000000000)
Dim key As String = "4aopMWtb_LTkwYNSJToE"
Dim text As String = appid & q & salt & key
Dim sign As String = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text, "MD5")
sign = sign.ToLower
Dim ScriptControl As Object, data As Object, JscriptCode As String
JscriptCode = "function toUrl() {return encodeURI('" & q & "')}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
.Language = "Javascript"
.Timeout = -1
.AddCode(JscriptCode)
text = .Run("toUrl")
End With
Dim url As String= "http://api.fanyi.baidu.com/api/trans/vip/translate?q=" & text & "&from=" & from & "&to=" & [To] & "&appid=" & appid & "&salt=" & salt & "&sign=" & sign
Dim rqst As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)
Dim rsps As System.Net.HttpWebResponse = rqst.GetResponse
Dim stm As System.IO.Stream = rsps.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
rsps.Close
stm.Close
reader.close
JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
.Language = "Javascript"
.Timeout = -1
.AddCode(JscriptCode)
data = .Run("toObject", str)
End With
output.show(str)
For Each o As object In data.trans_result
output.show(o.src)
output.show(o.dst)
Next