Asp.net example of API code (vb.net)


#1

Hi
I am trying to use the web API to get data. I have seen the C# example which uses a console application. However does anybody have a asp.net version of thsi code. I tried to convert to vb.net and use in my web app. But I cant seem to get the request right. any help would be much appreciated. I hve an API key and all thsi is configured, I am having a problem with the request and passing the file data

Public Shared Function GetRequest(ByVal image_path As String) As String
Dim bytes As Byte() = File.ReadAllBytes(image_path)
Dim imagebase64 As String = Convert.ToBase64String(bytes)

    Dim request As HttpWebRequest = WebRequest.Create(ApiURL)
    request.ContentLength = bytes.Length

    Dim newStream As Stream = request.GetRequestStream()
    newStream.Write(bytes, 0, bytes.Length)
    newStream.Close()

    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
    Dim receiveStream As Stream = response.GetResponseStream()
    Dim readStream As StreamReader = New StreamReader(receiveStream, Encoding.UTF8)
    Dim strContent As String = readStream.ReadToEnd()

    Return strContent
End Function

any help wouldbe much appreciated


#2

I was wondering if anybody had any thoughts on the above - I am passing through the correct URL and my key

Any help would be much appreciated