使用VB.NET在URL HTTP Web请求上发布JSON

时间:2014-06-27 17:02:23

标签: json vb.net http post wit.ai

我正在使用名为Wit.ai的在线NLP API。我正在发送一个http网络请求,我得到了一个回复,并且一切正常。但是,现在我需要知道如何POST这个JSON:

 {
   "state": "email_or_text"
 }

作为此代码的补充:

 Function getJson()
    Dim editedText As String = TextBox1.Text.Replace(" ", "%20")
    Dim myHttpWebRequest = CType(WebRequest.Create("https://api.wit.ai/message?v=20140609&q=" + editedText + "&units=metric"), HttpWebRequest)
    myHttpWebRequest.Headers.Add("Authorization: Bearer <myauthcode>")
    Dim myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
    Dim myWebSource As New StreamReader(myHttpWebResponse.GetResponseStream())
    Dim myPageSource As String = myWebSource.ReadToEnd()
    Return myPageSource
End Function

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

http://dotnetpad.com/9O883hmI查看此代码 它有一个POST方法的快速示例,可以让您开始发布您的JSON。 修改URL和内容字符串,然后单击“运行”并查看结果!