卷曲请求等效于VB.NET

卷曲请求等效于VB.NET,第1张

概述实际上,我正在尝试使用Watson服务,该服务向URL发出请求,并且cURL代码如下所示.如何在Visual Studio中使用Visual Basic语言执行此请求的等效 *** 作? curl -X POST -u "{username}":"{password}" —-header "Content-Type:application/json" --data "{\"input\": {\"text 实际上,我正在尝试使用Watson服务,该服务向URL发出请求,并且cURL代码如下所示.如何在Visual Studio中使用Visual Basic语言执行此请求的等效 *** 作?

curl -X POST -u "{username}":"{password}" —-header "Content-Type:application/Json" --data "{\"input\": {\"text\": \"Turn on the lights\"},\"context\": {\"conversation_ID\": \"1b7b67c0-90ed-45dc-8508-9488bc483d5b\",\"system\": {\"dialog_stack\": [\"root\"],\"dialog_turn_counter\": 1,\"dialog_request_counter\": 1}}}" "https://gateway.watsonplatform.net/conversation/API/v1/workspaces/25dfa8a0-0263-471b-8980-317e68c30488/message?version=2016-09-20"

有关更多信息,请参阅文档的URL以及解决方案cURL:

https://www.ibm.com/watson/developercloud/conversation/api/v1/

凭证和其他一切都很好.我把它从我的Node.Js示例中删除了:

var watson = require('watson-developer-cloud');var conversation = watson.conversation({  username: '1793094a-e543-4e3a-891d-4b619f21271d',password: 'xjmacpjHceRj',version: 'v1',version_date: '2016-09-20'});// Replace with the context obtained from the initial requestvar context = {};conversation.message({  workspace_ID: '7c7b099b-aed4-4d27-a379-8b2f33644600',input: {'text': 'Turn on the lights'},context: context},function(err,response) {  if (err)    console.log('error:',err);  else    console.log(JsON.stringify(response,null,2));});

VB.NET实现.

Dim myReq As httpWebRequest    Dim myResp As httpWebResponse    Dim reader As StreamReader    Try       myReq = httpWebRequest.Create("https://gateway.watsonplatform.net/conversation/API/v1/workspaces/7c7b099b-aed4-4d27-a379-8b2f33644600/message?version=2016-09-20")        myReq.Method = "POST"        myReq.ContentType = "application/Json"        myReq.headers.Add("Authorization",Convert.ToBase64String(EnCoding.Default.GetBytes("1793094a-e543-4e3a-891d-4b619f21271d:xjmacpjHceRj")))        Dim myData As String = "{input: {text: " + txtEnviar.Text + "},context: {conversation_ID: 1b7b67c0-90ed-45Dc-8508-9488bc483d5b\,system\: {dialog_stack: [root],dialog_turn_counter: 1,dialog_request_counter: 1}}}"        myReq.GetRequestStream.Write(System.Text.EnCoding.UTF8.GetBytes(myData),System.Text.EnCoding.UTF8.GetBytes(myData).Count)        myResp = myReq.GetResponse        Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)        Dim myText As String        myText = myreader.ReadToEnd()        txtMuestra.Items.Add(myText)        Catch ex As Exception            txtMuestra.Items.Add(ex)    End TryEnd Sub

但是我收到了身份验证错误.我想发送身份验证的方法未经头部授权是不正确的.我不是VB.NET的用户,所以这就是为什么我有我的并发症.

解决方法
Dim myReq As httpWebRequestDim myResp As httpWebResponsemyReq = httpWebRequest.Create("https://meineURI.net")myReq.Method = "POST"myReq.ContentType = "application/Json"myReq.headers.add("Authorization","Basic " & Convert.ToBase64String(EnCoding.UTF8.GetBytes("username:password")))Dim myData As String = "yourDataHere"myReq.GetRequestStream.Write(System.Text.EnCoding.UTF8.GetBytes(myData),System.Text.EnCoding.UTF8.GetBytes(myData).Count)myResp = myReq.GetResponseDim myreader As New System.IO.StreamReader(myResp.GetResponseStream)Dim myText As StringmyText = myreader.ReadToEnd
总结

以上是内存溢出为你收集整理的卷曲请求等效于VB.NET全部内容,希望文章能够帮你解决卷曲请求等效于VB.NET所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1236095.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存