使用VB.NET在URL HTTP Web请求上发布JSON [英] Post JSON on URL HTTP Web Request with VB.NET

查看:1195
本文介绍了使用VB.NET在URL HTTP Web请求上发布JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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"
 }

作为此代码的补充:

 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

感谢您的帮助!

推荐答案

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

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!

这篇关于使用VB.NET在URL HTTP Web请求上发布JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆