-1

My cross team member has created an API in APIM which I have to use for an existing .net application. He shared the postman collection and environment. I have imported it and successfully got the results back using Postman.

I have to call this API from an existing .net application and I don't know how to do it. Any pointers/inputs/help will be really appreciated.

Daniel
  • 2,355
  • 9
  • 23
  • 30
Tappy
  • 95
  • 1
  • 10
  • Make a simple rest call to the endpoint from your application. Check samples to call the webservice from your application. https://visualstudiomagazine.com/articles/2017/06/01/calling-web-services.aspx – VinuBibin Jan 10 '19 at 15:08

1 Answers1

0

Following is the solution I have implemented. I hope it helps someone. -- I used HttpClient to make the call and get the token.

Dim client = New HttpClient()

client.BaseAddress = "https://dev-azure.com" 'want the response to be JSON. client.DefaultRequestHeaders.Accept.Clear() client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))

        'Build up the data to POST.
        Dim postData As List(Of KeyValuePair(Of String, String)) = New List(Of KeyValuePair(Of String, String))()
        postData.Add(New KeyValuePair(Of String, String)("grant_type", "yourValue"))
        postData.Add(New KeyValuePair(Of String, String)("client_id", "yourvalue"))
        postData.Add(New KeyValuePair(Of String, String)("client_secret", "yourvlaue"))
        postData.Add(New KeyValuePair(Of String, String)("resource", yourvlaue))
        Dim content = New FormUrlEncodedContent(postData)

        'Post to the Server And parse the response.
        Dim responseContent = client.PostAsync("token", content).Result

        If (responseContent.StatusCode = HttpStatusCode.OK) Then
            Dim jsonString = responseContent.Content.ReadAsStringAsync().Result
            Dim responseData = JsonConvert.DeserializeObject(jsonString)
            accessToken = responseData("access_token")
        End If
    End Using
Tappy
  • 95
  • 1
  • 10