Post JSON on URL HTTP Web Request with VB.NET

吃可爱长大的小学妹 提交于 2019-12-01 04:49:18

问题


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:


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!



来源:https://stackoverflow.com/questions/24457191/post-json-on-url-http-web-request-with-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!