MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.19k stars 21.33k forks source link

Simple vb.net function to simply obtain a shortened url #123180

Closed mmichaels1970 closed 2 months ago

mmichaels1970 commented 2 months ago

Since I'm already sending SMS, I needed to simply figure out how to do the url shortening. Below is vb.net designed to simply get a shortened url.

 Public Class ShortenedUrl
     Public Property ShortUrl As String
 End Class

 <FunctionName("SendSMSUrlShortener")>
 Async Function Run(
 <HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route:=Nothing)> ByVal urltoshorten As String) As Task(Of String)
     Dim client = New HttpClient()
     Dim requestData = New With {Key .Url = urltoshorten}
     Dim requestBody = JsonSerializer.Serialize(requestData)
     Dim httpContent = New StringContent(requestBody, Encoding.UTF8, "application/json")
     Dim response = Task.Run(Function() client.PostAsync(urlshortener, httpContent))
     response.Wait()
     Dim content = Await response.Result.Content.ReadAsStringAsync()
     Dim url As String = ""
     Dim data = System.Text.Json.JsonSerializer.Deserialize(Of ShortenedUrl)(content)
     url = data.ShortUrl
     Return url
 End Function

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

TPavanBalaji commented 2 months ago

@mmichaels1970 It looks like your issue is resolved since you closed this thread. If there are further questions regarding this matter, please tag me in a comment. I will reopen it and we will gladly continue the discussion.