0

I have made a function to create a webrequest and load a api on my website to connect to ssh with parameters.

This is the function code:

    Public Function sshExec(ByVal command As String)

    Try
        Dim request As WebRequest = _
  WebRequest.Create("http://api.***.be/ssh.php?host=" + ComboBox1.Text + "&username=root&password=" + TextBox1.Text + "&command=" + command)
        ' Get the response.
        Dim response As WebResponse = request.GetResponse()
        ' Get the stream containing content returned by the server.
        Dim dataStream As Stream = response.GetResponseStream()
        ' Open the stream using a StreamReader for easy access.
        Dim reader As New StreamReader(dataStream)
        ' Read the content.
        Dim responseFromServer As String = reader.ReadToEnd()

        If responseFromServer.Contains("Login Failed") Then
            lblStatus.Text = "Login failed"
            lblStatus.ForeColor = Color.Red
        Else
            lblStatus.ForeColor = Color.Green
            lblStatus.Text = "Connected"
        End If

        TextBox2.Text = "http://api.***.be/ssh.php?host=" + ComboBox1.Text + "&username=root&password=" + TextBox1.Text + "&command=" + command

        ' Clean up the streams and the response.
        reader.Close()
        response.Close()

        Return responseFromServer

    Catch ex As Exception


    End Try

End Function

I made a textbox and when I use the function it puts the api link that it loads in a textbox. If I copy this and load it in my browser it works fine but with the webrequest it says:

Notice:  Cannot connect to 62.113.*** Error 0. php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/niel/public_html/api/Net/SSH2.php on line 831
Login Failed

Also, when I use the function a second time it doesn't load the page at all.

Anyone know what's wrong? Thanks in advance :)

Niel
  • 1
  • 2

1 Answers1

0

Most probably because you do not dispose the response, so simply call

response.Dispose()

after you closed it.

VladL
  • 12,769
  • 10
  • 63
  • 83