WebRequest from BV code to call a service and send multiple variable

by nik   Last Updated May 15, 2019 16:26 PM - source

I need to call an api service that is in C# from VB.net code and send 3 variables. When I use this code it is giving back error as I think where I send variables is not correct. Can you please guild me a correct way to send multiple variable from VB to call a service?

This is VB method to call the service:

        Dim apiUrl As String
        apiUrl = ConfigurationManager.AppSettings("URL").ToString()
        Dim hwr As HttpWebRequest
        hwr = WebRequest.Create(apiUrl + "api/Connect/acc")
        Dim postData = "Id =" & objSession.CurrentObject.Object_ID.ToString() & "&UserName =" & name & "&Reason =" & statusReason
        hwr.Method = "POST"

        Try
            Using wr As WebResponse = hwr.GetResponse()
                If CType(wr, HttpWebResponse).StatusCode = HttpStatusCode.OK Then
                    Using dataStream As Stream = wr.GetResponseStream()
                        Using reader As New StreamReader(dataStream)
                            Dim responseFromServer As String = reader.ReadToEnd()
                            reader.Close()
                        End Using
                    End Using
                    wr.Close()
                End If
            End Using
        Catch ex As Exception
            '...handle error...
        End Try

and this is the method that is am calling in the API:

    [RoutePrefix("api/Connect")]
    Class
    .......
    [HttpPost]
    [Route("acc")]
    public void CancelTransaction(int Id, string UserName, string Reason)
    {
    ...
    }
Tags : c# vb.net api


Related Questions