使用 VB.NET 在 URL HTTP Web 请求上发布 JSON
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24457191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Post JSON on URL HTTP Web Request with VB.NET
提问by user3567163
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:
我正在使用一个名为 Wit.ai 的在线 NLP API。我正在发送一个 http web 请求,我得到了一个响应,一切都很好。但是,现在我需要知道如何发布这个 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!
谢谢你的帮助!
回答by firas489
Check this code at http://dotnetpad.com/9O883hmIit 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!
在http://dotnetpad.com/9O883hmI检查此代码 它有一个 POST 方法的快速示例,可以让您开始发布您的 JSON。修改 URL 和内容字符串,然后点击运行并查看结果!

