Curl command for html or vb.net

I am trying to access the smartsheet API. They have a sample code provided in curl to access it.

To access the list of sheets, create an HTTPS request using your favorite programming or scripting language. Below is an example of using curl from the linux command line:

curl https://api.smartsheet.com/1.0/sheets \
-H "Authorization: Bearer 0da6cf0d-848c-4266-9b47-cd32a6151b1f" \
-H "Assume-User: john.doe%40smartsheet.com"

      

How can I do this in vb.net or from an html form?

+3


source to share


2 answers


It's a pretty big item, but you can try this ...

Imports System.Net

      

and then...

Dim wHeader As WebHeaderCollection = New WebHeaderCollection()

wHeader.Clear()
wHeader.Add("Authorization: Bearer 0da6cf0d-848c-4266-9b47-cd32a6151b1f")
wHeader.Add("Assume-User: john.doe%40smartsheet.com")

Dim sUrl As String = "https://api.smartsheet.com/1.0/sheets"

Dim wRequest As HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(sUrl), HttpWebRequest)

'wRequest.ContentType = "application/json" ' I don't know what your content type is
wRequest.Headers = wHeader
wRequest.Method = "GET"

Dim wResponse As HttpWebResponse = DirectCast(wRequest.GetResponse(), HttpWebResponse)

Dim sResponse As String = ""

Using srRead As New StreamReader(wResponse.GetResponseStream())
    sResponse = srRead.ReadToEnd()
End Using

      

I am not familiar with the smartsheet API, but you can use it as a starting point.



If you are using a proxy you will need to add ...

Dim wProxy As IWebProxy = WebRequest.GetSystemWebProxy()
wProxy.Credentials = System.Net.CredentialCache.DefaultCredentials

      

and specify the proxy when making the request ...

wRequest.Proxy = wProxy

      

+6


source


To create a web request in VB.Net you can use the class HttpWebRequest

.

-H

argument
to curl creates an additional header. To add headers to HttpWebRequest

, you simply add them to .WebHeaderCollection

Headers



Example:

Dim myHttpWebRequest = CType(WebRequest.Create("https://api.smartsheet.com/1.0/sheets"), HttpWebRequest)
myHttpWebRequest.Headers.Add("Authorization: Bearer 0da6cf0d-848c-4266-9b47-cd32a6151b1f")
myHttpWebRequest.Headers.Add("Assume-User: john.doe%40smartsheet.com")
Dim myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

      

+2


source







All Articles