如何在VB.NET中格式化curl API调用,对主URL之后的部分进行处理

时间:2019-04-03 21:33:06

标签: vb.net curl

我有一个供应商API curl示例,我试图弄清楚如何在VB.net中使用。注意:我可以使用几行代码在Google Apps脚本中执行此操作,并将结果放入表格中,但它必须在VB.NET中。我可以连接到“基本” URL,并获得包含我的凭据的200返回代码。

apps脚本非常简单:         var url ='https://'+ TheURL +'/helpdesk/WebObjects/Helpdesk.woa/ra/StatusTypes?' +凭证;

结果表明这应该返回一个json字符串:

    [{"id":1,"type":"StatusType","statusTypeName":"Open"},...

这是供应商提供的curl示例:

    $ curl "https://localhost/helpdesk/WebObjects/Helpdesk.woa\
    > /ra/StatusTypes\
    > ?apiKey=v32lXMFAi7dl3zGrtETArXqKVF8svfAfXZpIwC0P"

在VB.NET中,我添加了一个“ / ra / StatusTypes \”,它会中断-我认为关于VB.NET,我对此API缺少某些东西,但是所有示例都很简单。

    Dim uri As String = "https://" & TheURL & "/helpdesk/WebObjects/Helpdesk.woa"

    'Dim uri As String = "https://" & TheURL & "/helpdesk/WebObjects/Helpdesk.woa/ra/StatusTypes"  '<< This line does not work
    Dim request As Net.HttpWebRequest = Net.HttpWebRequest.Create(uri)
    request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(LoginID + ":" + APassword)))
    Dim response As WebResponse = request.GetResponse() ' Get the response.
    Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)   ' Display the status.
    'Console.ReadLine()
    Dim dataStream As Stream = response.GetResponseStream()
    Dim reader As New StreamReader(dataStream)
    Dim responseFromServer As String = reader.ReadToEnd()
    Console.WriteLine(responseFromServer)
    ' Console.ReadLine()
    reader.Close()
    response.Close()

0 个答案:

没有答案