Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl command to html or vb.net

Tags:

html

curl

vb.net

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

To access your Sheet list, construct an HTTPS request using your favorite programming or scripting language. Here is an example using the curl from a 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 do I do that in vb.net or from a html form?

like image 791
need_the_buzz Avatar asked Jul 18 '26 14:07

need_the_buzz


2 Answers

This is a rather large subject but at it's most simple you could 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'm unfamiliar with the smartsheet API but you can use this as a start 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 you make the request...

wRequest.Proxy = wProxy
like image 134
Ciarán Avatar answered Jul 20 '26 05:07

Ciarán


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

The -H argument in curl creates an extra header. To add headers to a HttpWebRequest you simply add them to the 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)
like image 43
sloth Avatar answered Jul 20 '26 07:07

sloth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!