2013-09-26 82 views
0

我已經創建了一個函數來創建webrequest並在我的網站上加載api以通過參數連接到ssh。Webrequest在第二次使用時不能在函數中工作

這是函數代碼:

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 

此外,當我使用功能的第二次不加載所有的頁面。

任何人都知道什麼是錯的?感謝提前:)

回答

0

最有可能的,因爲你不處置response,所以只需撥打

response.Dispose() 

你關閉後它。

+0

Dispose不是它所說的web響應的成員。 – Niel

+0

@Niel你使用哪個.net版本? http://msdn.microsoft.com/en-us/library/ff928381(v=vs.100).aspx – VladL

相關問題