我已经创建了一个函数来创建一个 webrequest 并在我的网站上加载一个 api 以使用参数连接到 ssh。
这是功能代码:
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
我制作了一个文本框,当我使用该函数时,它将加载的 api 链接放入文本框中。如果我复制它并将其加载到我的浏览器中,它可以正常工作,但是使用 webrequest 它会说:
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
此外,当我第二次使用该功能时,它根本不会加载页面。
有谁知道怎么了?提前致谢 :)