Post JSON on URL HTTP Web Request with VB.NET

2019-02-18 00:30发布

I am using an online NLP API called Wit.ai. I am sending an http web request, and I get a response, and that all works perfectly fine. However, now I need to know how to POST this JSON:

 {
   "state": "email_or_text"
 }

As an addition to this code:

 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

Thanks for your help!

1条回答
可以哭但决不认输i
2楼-- · 2019-02-18 00:48

Check this code at http://dotnetpad.com/9O883hmI it has a quick example of a POST method that can get you started on posting your JSON. Modify the URL and the content string and hit Run and see the results!

查看更多
登录 后发表回答